All Questions
8,181
questions
-7
votes
1
answer
50
views
WiggleSort: giving wrong output? [closed]
I am trying to solve LeetCode problem 324. Wiggle Sort II:
Given an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
You may assume the input array always ...
-3
votes
1
answer
77
views
Create a recursion function to respond with a different object [closed]
I'm a receiving the following data from a HTTP request to get all menus available:
[
{
"ID": "2",
"Name": "Home",
"ParentID": "1&...
-1
votes
1
answer
72
views
Shuffle the Array - LeetCode problem. 2 pointers approach fails [closed]
I am trying to solve LeetCode problem 1470. Shuffle the Array:
Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].
Return the array in the form [x1,y1,x2,y2,...,xn,...
0
votes
1
answer
46
views
Checking a candidate majority element: Does my simplification work with all cases?
Here are the details of the problem:
Given a sorted array arr of N elements.
A majority element in an array of size N is an element that appears more than N/2 times.
The task is to write a function ...
1
vote
1
answer
44
views
Find the right interval in a sorted arrary with duplicates given an input
I'm struggling with an array problem which I am not quite sure how to solve with binary search properly.
Say x is a sorted array, with duplicated values. Given a x_input, find the index of the two ...
1
vote
2
answers
167
views
Smallest element after xor
Starting with array of N positive integers, support Q queries. Each query contains a positive integer i. To answer the query, replace each element of the array with the result of xoring it with i, ...
-1
votes
1
answer
34
views
Why I receive an unknown variable error in my function?
I'm using AlgoBuild and inside the "input_vet()" function there's a while loop and in its condition I recall the variable N, which I assign a value in the main, and shows a unknown variable ...
0
votes
1
answer
50
views
Sorting with AlgoBuild. Why do I get an index is out of range error?
I am using AlgoBuild to make a program that sorts numbers.
This is my attempt:
AlgoBuild translates this chart to the following pseudo code:
PROGRAM main
INPUT int D
FOR i = 0; i < D; i = ...
3
votes
4
answers
134
views
sorting algorithm in O(n) according a specific condition
Given an array A with n−1 numbers where n = 2^k
for some integer k. One of the values appears exactly n/2
another appears exactly n/4, and so on. More formally, for all 1 ≤ k ≤ log n exists a value ...
1
vote
3
answers
122
views
Generate read-address and write address for zig-zag scan of NxN matrix
In my hardware design, data needs to be accessed in zig-zag fashion. I have a solution that gives me read-address sequence for an 8x8 matrix such that we are reading it in zig-zag way. However, I am ...
1
vote
1
answer
102
views
algorithm to detect pools of 0s in a matrix
I'm writing an algorithm that detects regions of contiguous empty cells that are completely surrounded (orthogonally) by filled cells and do not extend to the edge of the grid. Let's call such regions ...
2
votes
2
answers
120
views
Is there a way to search an array of arrays for matching properties and if they match, make sure they aren't in adjacent positions?
I have been wracking my brain for a week on this problem and would appreciate any help or suggestions. I have a form that collects the users first name, last name and song. It stores those values in ...
1
vote
1
answer
38
views
How do I conditionally deep merge objects in JavaScript with multiple keys
The project I am working on is a trilingual dictionary. I have a database of words, and each word contains (among other things) an array of spelling variations and an array of objects representing ...
2
votes
1
answer
102
views
Median of two sorted-arrays algorithm for O(log(m+n))
Median of two sorted-arrays is a quite well known problem in leetcode. Real implementation of O(log(min(m,n))) solution is quite straight forward but not of O(log(m•n)).
The basic idea is removing ...
-1
votes
1
answer
103
views
Ways to match elements of two sets [closed]
Consider this problem:
There are two sets of N elements each, 1 <= N <= 21. I need to pair each element from set #1 to a distinct element of set #2 with restrictions. Input also contains a ...