# Finding MEX of a changing set

I am trying to create a method add that adds elements x to the set one by one and returns MEX (=minimum non-negative number not in the set) of the list at each point. class Mex: def __init__(self): self.mex = set() def add(self, x): self.mex.add(x) mex = 0 while mex in self.mex: mex += 1… Read More Finding MEX of a changing set

# How can I fix my Binary Search code not working as expected?

I’m trying to perform my first binary search in javascript. But I’m failing to see what’s holding me back from getting the result I would expect from my code. This is my code: function search(arr, target, start = 0, end = arr.length – 1) { if (start > end) { console.log(‘Not found!’); return -1; }… Read More How can I fix my Binary Search code not working as expected?

# How can I get unique arrays in Python?

I got a fairly large array of arrays of length 2 (List[List[int, int]]) How can I unique arrays of them? Preferably without using different libraries I’ve seen several solutions that use numpy, but I’m unlikely to be able to use this in olympiads # Example input: nums = [[2, 9], [3, 6], [9, 2], [6,… Read More How can I get unique arrays in Python?

# LeetCode #849: Maximize Distance to Closest Person

I am trying to solve the problem in the link below from LeetCode: LeetCode: #849 But, I ask because I don’t understand some edge case below: Input: [1, 0, 0, 1] Expected: 1 I believe the rule returns the result value as shown below: Figure #1 The following image shows my edge case outcome based… Read More LeetCode #849: Maximize Distance to Closest Person

# How to find a missing number if a range of millions of numbers in an array?

I want to get the first missing number in a range of millions of numbers. For example, I have an array with n number of elements. And it starts from 0. And in between for example, after 4380, 4381 is missing and is continued with 4382. So, how can I find that 4381? I have… Read More How to find a missing number if a range of millions of numbers in an array?

# Algorithm to create a singly linked list

I have an algorithm that should create a singly linked list from a textbook. It barely touched on any examples, so I would need some help figuring it out (still new to C.) Essentially, the algorithm runs as follows: Algorithm: CREATE (HEAD, ITEM) 1. [Create NEW node] a) Allocate memory for NEW node. b) IF… Read More Algorithm to create a singly linked list

# I'm getting an "Execution Timed Out" error?

I’m trying to improve my algorithm skills. When I run my code, I get an "Execution Timed Out" error. Pseudocode [This is writen in pseudocode] if(number is even) number = number / 2 if(number is odd) number = 3*number + 1 My Code def hotpo(n): calculator = 0 while n >= 1: if n %… Read More I'm getting an "Execution Timed Out" error?

# Maximize the result for given array of values

I have an array of values example: [[1,15], [3,20], [4,30]] each element holds two values, the amount we need to pay at 0th index and items we can collect at 1st index. Also, I have a budget of 4. For this example, I can collect the elements [[1,15], [3,20]] because 1+3 = 4 which matches… Read More Maximize the result for given array of values