All Questions
8,176
questions
0
votes
1
answer
37
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
164
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
30
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
45
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
121
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
101
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
119
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
37
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
101
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 ...
4
votes
2
answers
179
views
Count divisible elements in subarray
I am trying to solve the following exercise:
There is an array of positive integers with size N given 1 <= N <= 2*105. Each element of the array is at most 105 at all times.
After reading in ...
1
vote
1
answer
74
views
How to find the maximum number possible in an array given constraints?
I'm working on a problem where I need to construct an array of size N such that the array adheres to the following constraints:
The first element of the array is always 0 (arr[0] = 0).
The difference ...
-5
votes
1
answer
62
views
How to process two very large JSON files with Python? [closed]
I have two files named smaller_file.json and larger_file.json. While both have the potential to be quite large, reaching over 200MB, the smaller_file.json will always be the smaller of the two.
I want ...