Problem Statement: You are given an array, you need to find the maximum sum of subsequence where no 2 numbers in the sequence are adjacent. So {3, 4, 5, 6} The max is 10 {6, 4}. Solution The solution is very simple. We take 2 …
Problem Statement: You are given an unsorted array, and an integer K. You need to get all distinct pairs with difference equal to k. Example Input: arr = {1, 5, 4, 2}, k = 3 Output: 2 There are 2 pairs with difference 3, the …
Problem Statement: You are given an array and has a difference of atmost k. Given a key ‘x’, we need to find the index value of ‘x’. Example Input : {1, 2, 3, 4, 3} k = 1 x = 3 Output : 2 First …
Problem Statement: You are given an array of repeating elements. You need to find and print the majority element. An element that appears more tha n/2 times, is called as majority element. Example Input : {3, 3, 4, 2, 4, 4, 2, 4, 4} Output …
Problem Statement: You are given an unsorted array, you need to get the maximum and minimum element of the array using minimum comparisons. Solution There are multiple ways to solve this problem: 1. Linear search: Here we simply search the whole array and update minimum and …
Problem Statement: You are given an sorted ascending array, you need to find the fixed point. A fixed point is an element in the array, such that index i and arr are same. Example Input: {-7, -4, 0, 3, 6} Output: 3 Because arr == 3 …
Problem Statement: You are given list of words, you need to print all the combinations of phrases that can be formed by picking one word from each list. Example s = {{“I”, “You”}, {“love”},{“programming”}} OUTPUT “I love programing” “You love programming” Solution We need …
Problem Statement: You are given 2 strings you need to return the longest common subsequence between two strings. Example str1 = ABC str2 = AC Output: 2 The LCS of the 2 strings is "AC" hence 2. Solution The solution is similar to LCS, but …
Problem Statement: You are given a string, you need find the 1st repeated word in a string. Example Input: : "I am what I am" Output: I Here "I" is the first repeated word in the string. Solution The solution is very simple. Here …