Connect n ropes: There are given n ropes of different lengths, we need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. We need
Array
Get Minimum element in O(1) from input numbers or Stack
Question : Get Minimum element in O(1) from Input Numbers or Stack
– With any traditional way we can’t get minimum element in O(1)
– so we need to come up with different data structure.
Find an index i such that Arr [i] = i in array of n distinct integers sorted in ascending order.
Given an array of n distinct integers sorted in ascending order, write a function that returns a Fixed Point in the array such that Arr[i] = i .
If there is any Fixed Point present
… Read More If there is any Fixed Point present
Check a String is SUBSEQUENCE of another String Find Minimum length for that ( DNA Matching )
Main DNA sequence(a string) is given (let say strDNA) and another string to search for(let say strPAT).
You have to find the minimum length window in strDNA where strPAT is subsequence.
… Read More You have to find the minimum length window in strDNA where strPAT is subsequence.
Code Chef PRGIFT Solution
Today is chef’s friend’s birthday. He wants to give a gift to his friend. So he was desperately searching for some gift here and there.
Fortunately, he found an array a of size n lying
… Read More Fortunately, he found an array a of size n lying
Find and print longest consecutive number sequence in a given sequence in O(n)
Ex: Input: 1 2 5 3 6 8 7 Output: 5 6 7 8
As given in Above example we need to find Longest Consecutive sequence in O(n)
I have implemented in O(n) considering by
Find min element in Sorted Rotated Array (With Duplicates)
Problem: Find the minimum element in a sorted and rotated array if duplicates are allowed:
Example: { 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 2} output: 0
Algorithm:
… Read More Example: { 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 2} output: 0
Algorithm:
This problem
Find min element in Sorted Rotated Array (Without Duplicates)
Problem: Find the minimum element in a sorted and rotated array if duplicates not allowed:
Example: {3, 4, 5, 6, 7, 1, 2} output: 1
… Read More Example: {3, 4, 5, 6, 7, 1, 2} output: 1
Algorithm:
This problem can be easily solved in O(n) time
CodeChef Code SGARDEN
This time Sheriff gathered all the bandits in his garden and ordered them to line up. After the whistle all bandits should change the order in which they stand.
Sheriff gave all the bandits numbers
… Read More Sheriff gave all the bandits numbers
CodeChef’ RRCOPY
Def:
You had an array of integer numbers. You also had a beautiful operations called “Copy-Paste” which allowed you to copy any contiguous sub-sequence of your array and paste it in any position of your
… Read More You had an array of integer numbers. You also had a beautiful operations called “Copy-Paste” which allowed you to copy any contiguous sub-sequence of your array and paste it in any position of your