Example: array = {1, 2, 3, 4, 5, 6, 7, 8, 9}; k = 30 Output: 4 This is because the sub array This problem can be solved with “two pointers with sliding window approach” solution. Algorithm: Step 1: Increase right pointer till the sum is …
2 strings are said to be isomorphic, if one letter in the first string can be replaced by another letter in the second string. Example 1: string_1 = add string_2 = egg Output: True Here “a” can be replaced by “e” and “d” can be replaced …
A majority element, is an element that is repeated more than half of the times. Example: Output: 4 Total number of elements are 9, and 4 is repeated 5 times. It has repeated more than half of the times. We can solve this problem by using …
Example 1: Input: Output: 1 We shall use 2 pointers to solve this problem. Below are steps how the solution works: Frist we check arr < arr, then we return the arr value. Else Compute the mid element If arr > arr, then we know that …
Input: Output: 6 Because, are continuous and has the largest product 6. The steps of the working of the solution is as below: Take 2 variables “front_product” and “back_product”. front_product will always calculate from front of the array. back_product will always calculate from back of the …
Example: Input: "prodevelopertutorial is a good website", Output: " website good a is prodevelopertutorial". The solution is as follows: Step 1: Reverse the whole string. Step 2: Reverse individual words in the string. Along with the above 2 steps, we need to remove leading and trailing spaces, …
In reverse polish notation, operands will be first followed by operators. For example, 2 – 3 in reverse polish notation will be 2 3 – 4 + 5 – 6 will be written as 4 5 + 6 – Solution explanation: We can solve this by …
Example: 3 -> 4 -> 5-> 1 -> 2 Output: 1 -> 2 -> 3 -> 4 -> 5 Merge sort is a divide and conquer algorithm. Here we divide the elements into smaller parts, then while merging them, we merge according to sorted order. Example: …