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
Interview Questions
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.
Add Sub Multiply very large number stored as string
Very large number like 2994320121 and 125346232 is given in character string.
You need to add, subtract and multiply two numbers and store number in character array only.
Logic
1) First way to create a
… Read More You need to add, subtract and multiply two numbers and store number in character array only.
Logic
1) First way to create a
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
Check Binary Tree is Binary Search Tree or not
To search Binary Search Tree
First lets understand characteristics of BST
• The left subtree of a node contains only nodes with keys less than the node’s key.
• The right subtree of a node
… Read More First lets understand characteristics of BST
• The left subtree of a node contains only nodes with keys less than the node’s key.
• The right subtree of a node