procedure Shortest-Path-Faster-Algorithm(G, s) 1 for each vertex v ≠ s in V(G) 2 d(v) := ∞ 3 d(s) := 0 4 push s into Q 5 w
Given an undirected weighted graph, a start, and an end point. You need to find the shortest path to that end point, but throw an error if multiple shortest pat
About the code The maximum sum subarray problem is the task of finding a contiguous subarray with the largest sum, within a given one-dimensio
This is a problem from competitive programmer's handbook: We are given the prices of k products over n days, and we want to buy each product exactly once. Howev
Source: Google Code Jam. https://code.google.com/codejam/contest/10224486/dashboard#s=a&a=1 We're asked to calculate Prob(K successes from N trials) where
I implemented the Largest Triple Products algorithm, but I use sort which makes my time complexity O(nlogn). Is there a way to implement it without a temporary
I am currently studying about Algorithms & Data Structures and while I was reading over the Book of Algorithms 4th edition, I discovered the Bag data-struct
My task is to output the current century of a given date. The date can be represented as a string; for example, 19.03.2022. How can I retrieve the year and cent
I was working on a problem where you have to square the numbers in a sorted array on leetcode. Here is the original problem Given an array of integers A sor
I came across this problem in a practice interview. I don't want a direct answer, just some help with the intuition of the problem, both your brute force thinki
As a small example, say I have N=6 elements { 0.03, 0.25000039, 1.391, 500.1, 0.5000001, 1.75001 } and K=3 then the combination { 0.25000039, 0.5000001, 0.
I have a problem on which I am working where I need to count the number of words in a string without using the split() function in Python. I thought of an appro
“⊕” is the bitwise XOR operation. I think Karatsuba’s algorithm may be used to solve the problem, but when I try to use XOR instead of
I'm researching on how to find k values in the BST that are closest to the target, and came across the following implementation with the rules: '?' Matches
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