A disjoint set with only path compression implemented is like this: // In cpp. int Find(int x) { return f[x] == x ? x : f[x] = Find(f[x]); } int Union(int a, i
I recently had my Amazon interview for SDE. I was asked to design a stack which does push, pop and min in O(1). I got the logic and implemented the push of the
I provide two data structures, cart_info and map_case, and get the result real_combinationby the algorithm. This algorithm is implemented in python import itert
Given a undirected graph that it has ordinary edges and specific edges, our goal is to find the sum of the shortest path's weight between two vertices(start ve
So this is the classic problem of finding a counterfeit coin among a set of coins using only a weighing balance. For completeness, here is one example of such a
I have a very inefficient way of counting the combinations of N/2 items from an array of size N. What I do is sort the array to begin with and then loop through
I have a dictionary something like this: { 'firstName': 'abc', 'lastName': 'xyz', 'favoriteMovies': ['Star Wars', 'The lone ranger'], 'favo
I've been working on an implementation of Shamir's Secret Sharing, and was wondering if the prime number selected will impact on the security. This is mainly be
I’d like to perform amortized analysis of a dynamic array: When we perform a sequence of n insertions, whenever an array of size k fills up, we reallocate
I have two sequences of 8 unsigned bytes and I need to compute their cyclic convolution, which yields 8 unsigned 19 bits integers. As I repeat this million time
Here's an interesting problem I haven't managed to deal with yet. Given an arithmetic expression in Reverse Polish Notation, write a program to evaluate it. T
So this question came to my mind when solving some dijikstra's based leetcode problems. We have node, distance pairs in priority queue at each step. Having dupl
Why I created a duplicate thread I created this thread after reading Longest increasing subsequence with K exceptions allowed. I realised that the person who wa
I'm trying to write a program whose input is an array of integers, and its size. This code has to delete each element which is smaller than the element to the l
I am confused since google cannnot train their text generation models with each individuals personal vocabulary. I was trying to develop something similar but
An evil scientist has developed an injection that induces insatiable hunger in a fish. On giving this injection, a fish of size x can eat another fish of smalle
I have this question that is medium level and couldn't even think on how to solve this problem, my solution could be overkill as I have no idea on how to traver
I was trying to write a algorithm in javascript that returns all the possible 3 digit numbers numbers from a given array of length 6 For Example var arr = [1, 2
I have a set of axis aligned rectangles. When two rectangles overlap (partly or completely), they shall be merged into their common bounding box. This process w
Is there any method of solving the traveling salesman problem effective and that is not limited by space (as is the case of the Held-Karp algorithm), excepting