# Adobe Coding Interview Questions  Dell Interview Questions

Question 1. Shuffle the Array Leetcode Solution The problem Shuffle the Array Leetcode Solution provides us with an array of length 2n. Here 2n refers that the array length is even. We are then told to shuffle the array. Here shuffling does not mean that we need to randomly shuffle the array but a specific way is ...

Question 2. 3Sum Leetcode Solution Problem Statement   Given an array of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Notice: that the solution set must not contain duplicate triplets. Example #1 [-1,0,1,2,-1,4] ...

Question 3. Combination Sum Leetcode Solution The problem Combination Sum Leetcode Solution provides us an array or list of integers and a target. We are told to find the combinations that can be made using these integers any number of times that add up to the given target. So more formally, we can use the given ...

Question 4. Maximum Subarray Leetcode Solution Problem Statement   Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example nums = [-2,1,-3,4,-1,2,1,-5,4] 6 Explanation: [4,-1,2,1] has the largest sum = 6. nums = [-1] -1 Approach 1 (Divide and Conquer)   In this approach ...

Question 5. Find N Unique Integers Sum up to Zero Leetcode Solution The problem Find N Unique Integers Sum up to Zero Leetcode Solution, provides us with an integer. It asks us to return n unique integers that sum up to 0. So, the question is pretty simple to understand. So, before diving into the solution. Let us take a look at ...

Question 6. Find Common Characters Leetcode Solution Problem Statement   In this problem, we are given an array of strings. We need to print a list of all characters that appear in every string in the array(duplicates included). That is if a character appears 2 times in every string, but not 3 times, we need to have it ...

Question 7. Find All Numbers Disappeared in an Array Leetcode Solution Problem Statement   In this problem, we are given an array of integers. It contains elements ranging from 1 to N, where N = size of the array. However, there are some elements that have disappeared and some duplicates are present in their place. Our goal is to return an array ...

Question 8. Majority Element II Leetcode Solution In this problem, we are given an array of integers. The goal is to find all the elements which occur more than ⌊N / 3⌋ time in the array where N = size of the array and ⌊ ⌋ is the floor operator. We need to return an array of ...

Question 9. Relative Sort Array Leetcode Solution In this problem, we are given two arrays of positive integers. All elements of the second array are distinct and are present in the first array. However, the first array can contain duplicate elements or elements that are not in the second array. We need to sort the first array ...

Question 10. Unique Paths Leetcode Solution The problem Unique Paths Leetcode Solution states that you are given two integers representing the size of a grid. Using the size of the grid, the length, and breadth of the grid. We need to find the number of unique paths from the top left corner of the grid to ...

Question 11. Matrix Diagonal Sum Leetcode Solution Problem Statement   In Matrix Diagonal Sum problem a square matrix of integers is given. We have to calculate the sum of all the elements present at its diagonals i.e. elements at primary diagonal as well as secondary diagonal. Each element should be counted only once. Example mat = [[1,2,3], [4,5,6], ...

Question 12. How Many Numbers Are Smaller Than the Current Number Leetcode Solution Problem Statement   In this problem, we are given an array. For each element of this array, we have to find out the number of elements smaller than that element. i.e. for each i (0<=i<arr.length) we have to find out count of elements less than the number arr[i]. For that we ...

Question 13. Merge Sorted Arrays Leetcode Solution In the problem “Merge Sorted Arrays”, we are given two arrays sorted in non-descending order. The first array is not fully filled and has enough space to accommodate all elements of the second array as well. We have to merge the two arrays, such that the first array contains elements ...

Question 14. Search in Rotated Sorted Array Leetcode Solution Consider a sorted array but one index was picked and the array was rotated at that point. Now, once the array has been rotated you are required to find a particular target element and return its index. In case, the element is not present, return -1. The problem is generally ...

Question 15. Search Insert Position Leetcode Solution In this problem, we are given a sorted array and a target integer. We have to find its Search Insert Position. If the target value is present in the array, return its index. Return the index at which the target should be inserted so as to keep the order sorted(in ...

Question 16. Running Sum of 1d Array Leetcode Solution Problem Statement   In running sum of 1d array problem we have been given an array nums for which we have to return an array where for each index i in the result array  arr[i] = sum( nums … nums[i] ). Example  nums = [1,2,3,4] [1,3,6,10] Explanation: Running sum is :  ...

Question 17. Plus One Leetcode Solution Problem statement   In the problem ” Plus One”  we are given an array where each element in the array represents a digit of a number. The complete array represents a number. The zeroth index represents the MSB of the number.  We can assume that there is no leading zero in ...

Question 18. Kth largest element in an Array Leetcode Solutions In this problem, we have to return the kth largest element in an unsorted array. Note that the array can have duplicates. So, we have to find the Kth largest element in the sorted order, not the distinct Kth largest element. Example   A = {4 , 2 , 5 , 3 ...

Question 19. Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i Suppose you have an integer array. The problem statement asks to rearrange the array in such a way that the elements at even position in an array should be greater than all elements before it and the elements at odd positions should be less than the elements before it. Example   ...

Question 20. Minimum Delete Operations to make all Elements of Array Same Suppose we have an input of array with “x” number of elements. We have given a problem that we have to find the deletions operations, which should be the minimum that is required to make an equal array i.e., the array will consist of equal elements. Example   Input: [1, 1, ...

Question 21. Group Multiple Occurrence of Array Elements Ordered by first Occurrence You are given a question in which you have given an unsorted array with multiple occurrences of numbers. The task is to group all the multiple occurrences of array elements ordered by first occurrence. Meanwhile, the order should be the same as the number comes. Example   Input: [ 2, 3,4,3,1,3,2,4] ...

Question 22. Rearrange an Array Such that arr[i] is equal to i “Rearrange an array such that arr[i]=i”  problem states that you are given an array of integers ranging from 0 to n-1. Since all the elements may not be present in the array, then in place of them -1 is there. The problem statement asks to rearrange the array in such ...

Question 23. Maximum Number of Chocolates to be Distributed Equally Among k Students “The maximum number of chocolates to be distributed equally among k students” states that you are given n boxes that have some chocolates in it. Suppose there are k students. The task is to distribute the maximum number of chocolates among k students equally, by selecting consecutive boxes. We can ...

Question 24. Maximum Consecutive Numbers Present in an Array Problem Statement   Suppose you have an array of integers of size N. The problem “Maximum consecutive numbers present in an array” asks to find out the maximum count of consecutive numbers that could be scattered in an array. Example   arr[] = {2, 24, 30, 26, 99, 25} 3 Explanation: The ...

Question 25. Find duplicates in a given array when elements are not limited to a range The problem “Find duplicates in a given array when elements are not limited to a range” states that you have an array consisting of n integers. The problem statement it to find out the duplicate elements if present in the array. If no such element exists return -1. Example   [ ...

Question 26. Best Time to Buy and Sell Stock III Leetcode Solution Problem statement   In the problem “Best Time to Buy and Sell Stock  III,” we are given an array where each element in the array contains the price of the given stock on that day. The definition of the transaction is buying one share of stock and selling that one share ...

Question 27. Length of the largest subarray with contiguous elements The problem “Length of the largest subarray with contiguous elements” states that you are given an integer array. The problem statement asks to find out the length of the longest contiguous sub-array of which elements can be arranged in a sequence (continuous, either ascending or descending). The numbers in the ...

Question 28. Maximum Distance in Array The problem “Maximum Distance in Array” states that you are given “n” no. of arrays and all the arrays are given in ascending order. Your task is to find the maximum difference/absolute difference of two numbers in an array and we can define the maximum distance between two numbers as ...

Question 29. Contains Duplicate We are given an array and it may be containing duplicates elements or maybe not. So we need to check if it contains duplicate. Examples   [1, 3, 5, 1] true [“apple”, “mango”, “orange”, “mango”] true [22.0, 4.5, 3.98, 45.6, 13.54] false Approach   We can check an array in several ways ...

Question 30. Subset Sum Problem in O(sum) space Problem Statement   The “Subset sum in O(sum) space” problem states that you are given an array of some non-negative integers and a specific value. Now find out if there is a subset whose sum is equal to that of the given input value. Example   Array = {1, 2, 3, 4} ...

Question 31. Find Index of Closing Bracket for a Given Opening Bracket in an Expression Problem Statement   Given a string s of length/size n and an integer value representing the index of an opening square bracket. Find index of closing bracket for a given opening bracket in an expression. Example   s = "[ABC]" index = 0 8 s = "[C-[D]]" index = 3 5 s ...

Question 32. Best Time to Buy and Sell Stock Problem Statement   The problem “Best Time to Buy and Sell Stock” states that you are given an array of prices of length n, where the ith element stores the price of stock on ith day. If we can make only one transaction, that is, to buy on one day and ...

Question 33. Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space Problem Statement   You are given an array of integers. The problem “Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space” asks to shuffle all the numbers in the array such that the numbers which are like (x0, x1, x2, x3, y0, y1, y2, y3) will be shuffled like x0, y0, ...

Question 34. Minimum time required to rot all oranges Problem Statement   The problem “Minimum time required to rot all oranges” states that you are given a 2D array, every cell has one of the three possible values 0, 1 or 2. 0 means an empty cell. 1 means a fresh orange. 2 means a rotten orange. If a rotten ...

Question 35. Find Minimum In Rotated Sorted Array Problem Statement   “Find Minimum In Rotated Sorted Array” states that you are given a sorted array of size n which is rotated at some index. Find the minimum element in the array. Example   a[ ] = {5, 1, 2, 3, 4} 1 Explanation: If we arrange the array in sorted ...

Question 36. Find minimum number of merge operations to make an array palindrome Problem Statement   You are given an array of integers. The problem statement asks to find minimum number of merge operations to make an array palindrome, i.e. find out the minimum number of merging operations to be done on the array to make it a palindrome. Merging operation simply means that ...

Question 37. Minimize the maximum difference between the heights Problem Statement   You are given some heights of n towers and a number k. We can either increase the height of the tower by k or decrease the height by k, but just for once. The problem statement asks to minimize the maximum difference between the heights. That is to ...

Question 38. Sorted Array to Balanced BST In sorted array to balanced BST problem, we have given an array in sorted order, construct a Balanced Binary Search Tree from the sorted array. Examples   Input arr[] = {1, 2, 3, 4, 5} Output Pre-order : 3 2 1 5 4 Input arr[] = {7, 11, 13, 20, 22, ...

Question 39. Maximal Square In the maximal square problem we have given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s, and return its area. Example   Input: 1 0 1 0 0 0 0 1 1 1 1 1 1 1 1 Please click Like if you ...

Question 40. Merge Overlapping Intervals In merge overlapping intervals problem we have given a collection of intervals, merge and return all overlapping intervals. Example   Input : [[2, 3], [3, 4], [5, 7]] Output: [[2, 4], [5, 7]] Explanation: We can merge [2, 3] and [3, 4] together to form [2, 4] Please click Like if ...

Question 41. Median of Two Sorted Arrays Given two sorted arrays A and B of size n and m respectively. Find the median of the final sorted array obtained after merging the given two arrays or in other words, we say that find median of two sorted arrays. ( Expected time complexity: O(log(n)) ) Approach 1 for ...

Question 42. Search an Element in Sorted Rotated Array In search in sorted rotated array problem we have given a sorted and rotated array and an element, check if the given element is present in the array or not. Examples   Input nums[] = {2, 5, 6, 0, 0, 1, 2} target = 0 Output true Input nums[] = {2, ...

Question 43. 3 Sum In 3 Sum problem, we have given an array nums of n integers, find all the unique triplets that sum up to 0. Example   Input: nums = {-1, 0, 1, 2, -1, -4} Output: {-1, 0, 1}, {-1, 2, -1} Naive Approach for 3 Sum problem   The Brute force approach ...

Question 44. Most Frequent Element in an Array You are given an array of integers. The problem statement says that you have to find out the most frequent element present in an array. If there are multiple values that occurs the maximum number of times, then we have to print any of them. Example   Input [1, 4,5,3,1,4,16] Output ...

Question 45. Trapping Rain Water In Trapping Rain Water problem we have given N non-negative integers representing an elevation map and the width of each bar is 1. We have to find the amount of water that can be trapped in the above structure. Example   Let’s understand that by an example For the above elevation ...

Question 46. Jump Game In jump game we have given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able to reach the last index. Example   Input: arr = [2,3,1,1,4] ...

Question 47. Combination Sum In combination sum problem we have given an array of positive integers arr[] and a sum s, find all unique combinations of elements in arr[] where the sum of those elements is equal to s. The same repeated number may be chosen from arr[] an unlimited number of times. Elements ...

Question 48. Search in Sorted Rotated Array An element search in sorted rotated array can be found using binary search in O(logn) time. The objective of this post is to find a given element in a sorted rotated array in O(logn) time. Some example of a sorted rotated array is given. Example   Input : arr[] = {7,8,9,10,1,2,3,5,6}; ...

Question 49. Maximum Subarray In the Maximum Subarray problem we have given an integer array nums, find the contiguous sub array which has the largest sum and print the maximum sum subarray value. Example   Input nums[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4} Output 6 Algorithm   The goal is to find ...

Question 50. Merging Intervals In merging intervals problem we have given a set of intervals of the form [l, r], merge the overlapping intervals. Examples   Input {[1, 3], [2, 6], [8, 10], [15, 18]} Output {[1, 6], [8, 10], [15, 18]} Input {[1, 4], [1, 5]} Output {[1, 5]} Naive Approach for merging intervals   ...

Question 51. 4Sum In the 4Sum problem, we have given an integer x and an array a[ ] of size n. Find all the unique set of 4 elements in array such that sum of those 4 elements is equal to the given integer x. Example   Input  a[ ] = {1, 0, -1, ...

Question 52. Search Insert Position In the Search Insert Position problem, we have given an integer x and a sorted array a[ ] of size n. Find the appropriate index or position at which the given integer must be inserted if given integer, not in the array. If given integer present in the input array ...

Question 53. Find Peak Element Let’s understand Find Peak Element problem. Today we have with us an array that needs its peak element. Now, you must be wondering as to what do I mean by the peak element? The peak element is one which is greater than all its neighbours. Example: Given an array of ...

Question 54. Pascal Triangle Leetcode The Pascal Triangle is a very good Leetcode problem that is asked so many times in Amazon, Microsoft, and other companies. we have given non-negative integer rows, print first rows rows of the pascal triangle. Example   rows = 5 rows = 6 Please click Like if you loved this article? Types ...

Question 55. Container with Most Water Problem description : you are given n integers (y0, y1, y2 … yn-1) at n indices (i = 0,1,2 … n-1). Integer at i-th index is yi. Now, you draw n lines on a cartesian plane each connecting points (i, yi) and (i, 0). Find the maximum volume of water ...

Question 56. Subarray Sum Equals k Given an integer array and an integer k. Find total number of contiguous subarrays of given array whose sum of elements is equal to k. Example   Input 1: arr[] = {5,0,5,10,3,2,-15,4} k = 5 Output: 7 Input 2: arr[] = {1,1,1,2,4,-2} k = 2 Output: 4 Explanation : consider example-1 ...

Question 57. Quick Sort Quick Sort is a sorting algorithm. Given an unsorted array sort it using quick sort algorithm. Example Input: {8, 9, 5, 2, 3, 1, 4} Output: {1, 2, 3, 4, 5, 8, 9} Theory   It’s a Divide and Conquer sorting Algorithm. It picks a pivot element in the array, splits ...

Question 58. Subset sum problem In the subset sum problem, we are given a list of all positive numbers and a Sum. We need to check if there is a subset whose sum is equal to the given sum. Example   Input List of numbers: 1 2 3 10 5 sum: 9 Output Please click Like ...

Question 59. Merge Overlapping Intervals II Problem Statement   In the “Merge Overlapping Intervals II” problem we have given a set of intervals. Write a program that will merge the overlapping intervals into one and print all the non-overlapping intervals. Input Format   The first line containing an integer n. Second-line containing n pairs where each pair is ...

Question 60. Maximum Subarray Sum using Divide and Conquer Problem Statement   In the “Maximum Subarray Sum using Divide and Conquer” problem we have given an array of both positive and negative integers. Write a program that will find the largest sum of the contiguous subarray. Input Format   The first line containing an integer N. Second-line containing an array of ...

Question 61. Arrange given Numbers to Form the Biggest Number II Problem Statement   In the “Arrange given Numbers to Form the Biggest Number II” problem, we have given an array of positive integers.  Arrange them in such a way that the arrangement will form the largest value. Input Format   The first and only one line containing an integer n. Second-line containing ...

Question 62. Largest Subarray with Equal Number of 0’s and 1’s Problem Statement   In the “Largest Subarray with Equal Number of 0’s and 1’s” problem, we have given an array a[] containing only 0 and 1. Find the largest subarray with an equal number of 0’s and 1’s and will print the start index and end index of the largest subarray. ...

Question 63. Maximum Sum Increasing Subsequence Problem Statement   In the “Maximum Sum Increasing Subsequence” problem we have given an array. Find the sum of the maximum subsequence of the given array, that is the integers in the subsequence are in sorted order. A subsequence is a part of an array which is a sequence that is ...

Question 64. Number of Smaller Elements on Right Side Problem Statement   In the “Number of Smaller Elements on Right Side” problem, we have given an array a[]. Find the number of smaller elements that are on the right_side of each element. Input Format   The first and only one line containing an integer N. Second-line containing N space-separated integers. Output ...

Question 65. Elements Appear more than N/K times in Array Problem Statement   In the “Elements Appear more than N/K times in Array” problem we have given an integer array of size n. Find the elements which appear more than n/k times. Where k is the input value. Input Format   The first and only one line containing two integers N and ...

Question 66. Find the Maximum Repeating Number in Array Problem Statement   In the “Find the Maximum Repeating Number in Array” problem we have given an unsorted array of size N. Given array contains numbers in range {0, k} where k <= N. Find the number that is coming the maximum number of times in the array. Input Format   The ...

Question 67. Four Elements that Sum to Given Problem Statement   In four elements that sum to a given problem, we have given an array containing N elements that may be positive or negative. Find the set of four elements whose sum is equal to given value k. Input Format   First-line containing an integer N. Second-line containing an array ...

Question 68. Partition Problem Problem Statement   In the Partition problem, we have given a set that contains n elements. Find whether the given set can be divided into two sets whose sum of elements in the subsets is equal. Example   Input arr[] = {4, 5, 11, 9, 8, 3} Output Yes Please click Like ...

Question 69. Subarray with Given Sum Problem Statement   In the subarray with the given sum problem, we have given an array containing n positive elements. We have to find the subarray in which the sum of all the elements of the subarray equal to a given_sum. Subarray is obtained from the original array by deleting some ...

Question 70. Maximum Element in an Array which is Increasing and then Decreasing Problem Statement   In the given array which contains n elements. Elements are stored in such a way that first k elements are in increasing order and then n-k elements in decreasing from there, we need to find the maximum element in the array. Example   a)    Input array : [15, 25, ...

Question 71. Find the Lost Element From a Duplicated Array Problem Statement   Given two arrays A and B, one array is a duplicate of the other except one element. The one element is missing from either A or B. we need to find the lost element from a duplicated array. Example   5 1 6 4 8 9 6 4 8 ...

Question 72. Merge Two Sorted Arrays Problem Statement   In merge two sorted arrays problem, we have given two input sorted arrays, we need to merge these two arrays such that the initial numbers after complete sorting should be in the first array and remaining in the second array. Example   Input A[] = {1, 3, 5, 7, ...

Question 73. Count of Triplets With Sum Less than Given Value Problem Statement   We have given an array containing N number of elements. In the given array, Count the number of triplets with a sum less than the given value. Example   Input a[] = {1, 2, 3, 4, 5, 6, 7, 8} Sum = 10 Output 7 Possible triplets are : ...

Question 74. Merging Two Sorted Arrays Problem Statement   In merging two sorted arrays problem we have given two sorted arrays, one array with size m+n and the other array with size n. We will merge the n sized array into m+n sized array and print the m+n sized merged array. Example   Input 6 3 M[] = ...

Question 75. Find Triplet in Array With a Given Sum Problem Statement   Given an array of integers, find the combination of three elements in the array whose sum is equal to a given value X. Here we will print the first combination that we get. If there is no such combination then print -1. Example   Input N=5, X=15 arr[] = ...

Question 76. Sort 0s 1s and 2s in an Array Problem Statement   Given an array containing N elements where elements of the array are 0,1 or 2. Sort or Segregate 0s 1s and 2s in an array. Arrange all zeros in the first half, all ones in the second half and all twos in the third half. Example   Input 22 ...

Question 77. Smallest Positive Number Missing in an Unsorted Array Problem Statement   In the given unsorted array find the smallest positive number missing in an unsorted array. A positive integer doesn’t include 0. We can modify the original array if needed. The array may contain positive and negative numbers. Example   a. Input array : [3, 4, -1, 0, -2, 2, 1, ...

Question 78. Move All the Zeros to the End of the Given Array Problem Statement   In the given array move all the zeros which are present in the array to the end of the array. Here there is always a way exist to insert all the number of zeroes to the end of the array. Example   Input 9 9 17 0 14 0 ...

Question 79. Find Smallest Missing Number in a Sorted Array Problem Statement   In the “Find Smallest Missing Number in a Sorted Array” problem we have given an integer array. Find the smallest missing number in N sized sorted array having unique elements in the range of 0 to M-1, where M>N. Example   Input [0, 1, 2, 3, 4, 6, 7, ...

Question 80. First Repeating Element Problem Statement   We have given an array that contains n integers. We have to find the first repeating element in the given array. If there is no repeated element then print “No repeating integer found”. Note: Repeating elements are those elements that come more than once. (Array may contain duplicates) ...

Question 81. Multiplication of Previous and Next Problem Statement   Multiplication of Previous and Next: In the given array replace every element with the product of next and previous elements to it. And for the first element(a) we need to replace it with the product of next and itself, for  the last element(a[n-1]) we need to replace it ...

Question 82. A Product Array Puzzle Problem Statement   In a product array puzzle problem we need to construct an array where the ith element will be the product of all the elements in the given array except element at the ith position. Example   Input  5 10 3 5 6 2 Output Please click Like if you ...

Question 83. Find the first Repeating Number in a Given Array Problem Statement   There can be multiple repeating numbers in an array but you have to find the first repeating number in a given array (occurring the second time). Example   Input 12 5 4 2 8 9 7 12 5 6 12 4 7 Output Please click Like if you loved ...

Question 84. Print All Distinct Elements of the Array Problem Statement   We have an array of containing N integers which may be positive or negative. We have to print all distinct elements of the array. In other words, we can say that if a number occurs more than one time then we print only that number once. Example   Input ...

Question 85. Majority Element Problem Statement   Given a sorted array, we need to find the majority element from the sorted array. Majority element: Number occurring more than half the size of the array. Here we have given a number x we have to check it is the majority_element or not. Example   Input 5 2 ...

Question 86. Find the Missing Number Problem Statement   In finding the missing number from an array of 1 to N numbers we have given an array that contains N-1 numbers. One number is missing from an array of numbers from 1 to N. We have to find the missing number. Input Format   First-line containing an integer ...

Question 87. Isomorphic Strings Leetcode Solution Problem Statement   In this problem, we are given two strings, a and b. Our goal is to tell whether the two strings are isomorphic or not. Two strings are called isomorphic if and only if the characters in the first string can be replaced by any character(including itself) at all ...

Question 88. Is Subsequence Leetcode Solution Problem Statement   In this problem, we are given two different strings. The goal is to find out whether the first string is a subsequence of the second. Examples first string = "abc" second string = "mnagbcd" true first string = "burger" second string = "dominos" false Approach(Recursive)   This is easy ...

Question 89. To Lower Case Leetcode Solution The problem To Lower Case Leetcode Solution provides us with a string and asks us to convert all the upper case alphabets into lower case alphabets. We are required to convert all the upper case or lower case alphabets into lower case characters. So, the problem seems simple but before ...

Question 90. Find the Difference Leetcode Solution In this problem, we are given two strings. The second string is generated by shuffling the characters of the first string randomly and then adding an extra character at any random position. We need to return the extra character that was added to the second string. The characters will always ...

Question 91. Roman to Integer Leetcode Solution In the problem “Roman to Integer”, we are given a string representing some positive integer in its Roman numeral form. Roman numerals are represented by 7 characters that can be converted to integers using the following table: Note: The integer value of the given roman numeral will not exceed or ...

Question 92. Integer to Roman Leetcode Solution In this problem, we are given an integer and are required to convert into roman numeral. Thus the problem is generally referred to as “Integer to Roman” and this is Integer to Roman Leetcode Solution. If someone does not know about Roman numerals. In the old times, people did not ...

Question 93. Longest Substring Without Repeating Characters Given a string, we have to find the length of the longest substring without repeating characters. Let’s look into a few examples: Example   pwwkew 3 Explanation: Answer is “wke” with length 3 aav 2 Explanation: Answer is “av” with length 2 Approach-1 for Longest Substring Without Repeating Characters    Brute Force  ...

Question 94. Find Index of Closing Bracket for a Given Opening Bracket in an Expression Problem Statement   Given a string s of length/size n and an integer value representing the index of an opening square bracket. Find index of closing bracket for a given opening bracket in an expression. Example   s = "[ABC]" index = 0 8 s = "[C-[D]]" index = 3 5 s ...

Question 95. Remove brackets from an algebraic string containing + and – operators Problem Statement   You are given a string s of size n representing an arithmetic expression with parenthesis. The problem “Remove brackets from an algebraic string containing + and – operators” asks us to create a function that can simplify the given expression. Example   s = "a-(b+c)" a-b-c  s = a-(b-c-(d+e))-f a-b+c+d+e-f ...

Question 96. Reverse words in a string Problem Statement   “Reverse words in a string” states that you are given a string s of size n. Print the string in reverse order such that the last word becomes the first, second last becomes the second, and so on. Hereby string we refer to a sentence containing words instead ...

Question 97. Decode Ways In Decode Ways problem we have given a non-empty string containing only digits, determine the total number of ways to decode it using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Example   S = “123” Number of ways to decode this string is 3 If we ...

Question 98. Next Permutation In the next permutation problem we have given a word, find the lexicographically greater_permutation of it. Example   input : str = "tutorialcup" output : tutorialpcu input : str = "nmhdgfecba" output : nmheabcdfg input : str = "algorithms" output : algorithsm input : str = "spoonfeed" output : Next Permutation ...

Question 99. Longest Common Prefix using Sorting In the Longest Common Prefix using Sorting problem we have given a set of strings, find the longest common prefix. i.e. find the prefix part that is common to all the strings. Example   Input1: {“tutorialcup”, “tutorial”, “tussle”, “tumble”} Output: "tu" Input2: {"baggage", "banana", "batsmen"} Output: "ba" Input3: {"abcd"} Output: "abcd" ...

Question 100. Regular Expression Matching In the Regular Expression Matching problem we have given two strings one (let’s assume it x) consists of only lower case alphabets and second (let’s assume it y) consists of lower case alphabets with two special characters i.e, “.” and “*”. The task is to find whether the second string ...

Question 101. Valid Parentheses In Valid Parentheses problem we have given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. ( ) [ ] { } ...

Question 102. Longest Common Prefix using Trie In the Longest Common Prefix using Trie problem we have given a set of strings, find the longest common prefix. i.e. find the prefix part that is common to all the strings. Example   Input1: {“tutorialcup”, “tutorial”, “tussle”, “tumble”} Output: "tu" Input2: {"baggage", "banana", "batsmen"} Output: "ba" Input3: {"abcd"} Output: "abcd" ...

Question 103. Sort a String According to Another String Problem Statement   Given two input strings, a pattern and a string. We need to sort the string according to the order defined by the pattern. Pattern string has no duplicates and it has all characters of the string. Input Format   The first line containing a string s which we need ...

Question 104. Check if String can Become Empty by Recursively Deleting given Substring Problem Statement   In the “Check if string can become empty by recursively deleting given substring” problem we have given two strings “s” and “t”. We have to check if the given input string “s” can be deleted completely by deleting the given input sub-string “t” recursively. Note: Given sub-string should ...

Question 105. Smallest Palindrome after Replacement Problem Statement   In the “Smallest Palindrome after Replacement” problem we have given the input string contains lower case alphabets characters and dots(.). We need to replace all dots with some alphabet character in such a way that the resultant string becomes a palindrome. The palindrome should be lexicographically smallest. Input ...

Question 106. Check if String Follows Order of Characters by a Pattern or not Problem Statement   In the “Check if String Follows Order of Characters by a Pattern or not” problem we have to check if characters in the given input string follow the same order as determined by characters present in the given input pattern then print “Yes” else print “No”. Input Format   ...

Question 107. Split Four Distinct Strings Problem Statement   In the “Split Four Distinct Strings” problem we have to check if the given input string can split into 4 strings such that each string is non-empty and different from each others. Input Format   The first and only one lone containing string “s”. Output Format   Print “Yes” if ...

Question 108. Reverse String Without Temporary Variable Problem Statement   In the “Reverse String Without Temporary Variable” problem we have given a string “s”. Write a program to reverse this string without using any extra variable or space. Input Format   The first line containing the given string “s”. Output Format   Print the string which is reverse of the ...

Question 109. Count the Pairs at Same Distance as in English Alphabets Problem Statement   In the “Count of Pairs at Same Distance as in English Alphabets” problem we have given a string “s”. Write a program that will print the number of pairs whose elements are at the same distance as in English alphabets. Input Format   The first line containing the given ...

Question 110. Convert a String that is Repetition of a Substring of Length K Problem Statement   In the “Convert a String that is Repetition of a Substring of Length K” problem we have given a string “s” and an integer “k”. Write a program to check whether is it possible to convert it to a string that is the repetition of a substring with ...

Question 111. Nth Character in Concatenated Decimal String Problem Statement   In the “Nth Character in Concatenated Decimal String” problem we have given an integer value “n”. Write a program to find the Nth character in the string in which all decimals are concatenated. Input Format   The first and only one line containing an integer value n. Output Format   ...

Question 112. Compare Two Version Numbers Problem Statement   Given two input strings, which are in form of version numbers. A version number looks like a.b.c.d where a, b, c, d are integers. Therefore, the version number is a string in which numbers are separated by dots. We need to compare the two strings (version numbers) and ...

Question 113. Longest Common Subsequence with Permutations Problem Statement   In the “Longest Common Subsequence with Permutations” problem we have given two strings “s” and “t”. Find the longest string whose permutations are sub-sequences of the given two strings. Output longest must be sorted. Input Format   The first line containing a string “s”. The second line containing a ...

Question 114. Longest Palindrome can be Formed by Removing or Rearranging Characters Problem Statement   In the “Longest Palindrome can be Formed by Removing or Rearranging Characters” problem we have given a string “s”. Find the longest palindrome that can be constructed by removing or rearranging some characters or possibly zero characters from the string. There may be multiple solutions possible, you can ...

Question 115. Longest Common Prefix Word by Word Matching Problem Statement   In the “Longest Common Prefix using Word by Word Matching” problem, we have given N strings.  Write a program to find the longest common prefix of the given strings. Input Format   The first line containing an integer value N which denotes the number of strings. Next N lines ...

Question 116. Longest Common Prefix using Character by Character Matching Problem Statement   In the “Longest Common Prefix using Character by Character Matching” problem we have given an integer value N and N strings. Write a program to find the longest common prefix of the given strings. Input Format   The first line containing an integer value N which denotes the number ...

Question 117. Calculate Sum of all Numbers Present in a String Problem Statement   In the “Calculate Sum of all Numbers Present in a String” problem we have given a string “s”. This string contains some alphanumeric numbers and some English lowercase characters. Write a program that will calculate all the numbers present in that string and print the final answer. Input ...

Question 118. Lower Case To Upper Case Problem Statement   In the “Lower Case To Upper Case” problem, we have given a string “s” with only lower case letters. Write a program that will print the same string but with upper case letters. Input Format   The first and only one line containing a string “s”. Output Format   The ...

Question 119. Longest Common Prefix Using Binary Search II Problem Statement   In the “Longest Common Prefix Using Binary Search II” problem we have given an integer value N and N strings. Write a program that will print the longest common prefix of given strings. If there is no common prefix then print “-1”. Input Format   The first line containing ...

Question 120. Change Gender of a given String Problem Statement   In the “Change Gender of a given String” problem we have given a string “s”. Write a program that will toggle all the gender-specific words in the input string. Input Format   The first and only one line containing a sentence or string with spaces “s”. Output Format   Print ...

Question 121. Repeated Subsequence of Length Two or More Problem Statement   In the “Repeated Subsequence of Length Two or More” problem we have given the string “s”. Find if there is any subsequence of length two 0r more. The sub-sequences should not have the same character at the same position. Input Format   The first and only one line containing ...

Question 122. Online Algorithm for Checking Palindrome in a Stream Problem Statement   In the “Online Algorithm for Checking Palindrome in a Stream” problem, we have given a stream of characters(charcaters are received one by one). Write a program that will print ‘yes’ every time if the received characters till now form a palindrome. Input Format   The first and only one ...

Question 123. Check if Two given Strings are Isomorphic to each other Problem Statement   In the “Check if Two given Strings are Isomorphic to each other” problem we have given two strings s1 and s2. Write a program that says whether the given strings are isomorphic or not. Note: Two strings are said to be isomorphic if there is a one to ...

Question 124. Length of Longest valid Substring Problem Statement   In the “Length of Longest valid Substring” we have given a string that contains the opening and closing parenthesis only. Write a program that will find the longest valid parenthesis substring. Input Format   The first and only one line containing a string s. Output Format   The first and ...

Question 125. Arrange given Numbers to Form the Biggest Number II Problem Statement   In the “Arrange given Numbers to Form the Biggest Number II” problem, we have given an array of positive integers.  Arrange them in such a way that the arrangement will form the largest value. Input Format   The first and only one line containing an integer n. Second-line containing ...

Question 126. Check if a Linked list of Strings form a Palindrome Problem Statement   In the “Check if a Linked list of Strings form a Palindrome” problem we have given a linked list handling string data. Write a program to check whether the data forms a palindrom or not. Example   ba->c->d->ca->b 1 Explanation: In the above example we can see that the ...

Question 127. Sum of Left Leaves Leetcode Solutions In this problem, we have to find the sum of all left leaves in a binary tree.  A leaf that is called a “Left Leaf” if it is a left child of any node in the tree. Example     2 / \ 4 7 / \ 9 4 Sum is 13 ...

Question 128. Check if a given array can represent Preorder Traversal of Binary Search Tree The problem “Check if a given array can represent Preorder Traversal of Binary Search Tree” states that you are given a preorder traversal sequence. Now consider this sequence and find out if this sequence can represent a binary search tree or not? The expected time complexity for the solution is ...

Question 129. Print Right View of a Binary Tree Problem Statement   The problem “Print Right View of a Binary Tree” states that you are given a binary tree. Now you need to find the right view of this tree. Here, right view of the binary tree means to print the sequence as the tree looks when looked from the ...

Question 130. Iterative Method to find Height of Binary Tree Problem Statement   The problem “Iterative Method to find Height of Binary Tree” states that you are given a binary tree, find the height of the tree using the iterative method. Examples   Input 3 Input 4 Algorithm for Iterative Method to find Height of Binary Tree   The height of a tree ...

Question 131. Check if all levels of two Binary Tree are anagrams or not Problem Statement   The problem “Check if all levels of two Binary Tree are anagrams or not” says that you are given two Binary Trees, check if all the levels of the two trees are anagrams or not. Examples   Input true Input Please click Like if you loved this article? false ...

Question 132. Iterative Postorder Traversal Using Two Stacks Problem Statement   The problem “Iterative Postorder Traversal Using Two Stacks” states that you are given a binary tree with n nodes. Write the program for it’s iterative postorder traversal using two stacks. Example   Input   Please click Like if you loved this article? 4 5 2 6 7 3 1 ...

Question 133. Iterative method to find ancestors of a given binary tree Problem Statement   “Iterative method to find ancestors of a given binary tree” problem states that you are given a binary tree and an integer representing a key. Create a function to print all the ancestors of the given key using iteration. Example   Input  key = 6 5 2 1 Explanation: ...

Question 134. A program to check if a binary tree is BST or not Problem Statement   “A program to check if a binary tree is BST or not” states that you are given a binary tree and you need to check if the binary tree satisfies the properties of the binary search tree. So, the binary tree has the following properties:  The left subtree ...

Question 135. Binary Tree to Binary Search Tree Conversion In binary tree to binary search tree conversion problem, we have given a binary tree convert it to Binary Search Tree without changing the structure of the tree. Example   Input Output Please click Like if you loved this article? pre-order : 13 8 6 47 25 51 Algorithm   We do ...

Question 136. Sorted Array to Balanced BST In sorted array to balanced BST problem, we have given an array in sorted order, construct a Balanced Binary Search Tree from the sorted array. Examples   Input arr[] = {1, 2, 3, 4, 5} Output Pre-order : 3 2 1 5 4 Input arr[] = {7, 11, 13, 20, 22, ...

Question 137. Level order Traversal in Spiral Form In this problem we have given a binary tree,  print its level order traversal in a spiral form. Examples   Input Output 10 30 20 40 50 80 70 60 Naive Approach for Level order Traversal in Spiral Form   The idea is to do a normal level order traversal using a ...

Question 138. Lowest Common Ancestor Given the root of a binary tree and two nodes n1 and n2, find the LCA(Lowest Common Ancestor) of the nodes. Example   What is Lowest Common Ancestor(LCA)?   The ancestors of a node n are the nodes present in the path between root and node. Consider the binary tree shown in ...

Question 139. Binary Tree zigzag level order Traversal Given a binary tree, print the zigzag level order traversal of its node values. (ie, from left to right, then right to left for the next level and alternate between). Example   consider the binary tree given below Below is the zigzag level order traversal of the above binary tree Please ...

Question 140. Symmetric Tree In Symmetric Tree problem we have given a binary tree, check whether it is a mirror of itself. A tree is said to be a mirror image of itself if there exists an axis of symmetry through a root node that divides the tree into two same halves. Example   Please ...

Question 141. Longest Common Prefix using Trie In the Longest Common Prefix using Trie problem we have given a set of strings, find the longest common prefix. i.e. find the prefix part that is common to all the strings. Example   Input1: {“tutorialcup”, “tutorial”, “tussle”, “tumble”} Output: "tu" Input2: {"baggage", "banana", "batsmen"} Output: "ba" Input3: {"abcd"} Output: "abcd" ...

Question 142. Tree Traversal (Preorder, Inorder & Postorder) First, we need to know about what is Traversal in Binary Tree. Traversal is a type of method in which we visit all the nodes exactly once in some specific manner/order. Basically there are two types of traversal in Binary Tree: Breadth-First Traversal Depth  First Traversal We already know about ...

Question 143. Dijkstra Algorithm Dijkstra is the shortest path algorithm. Dijkstra algorithm is used to find the shortest distance of all nodes from the given start node. It logically creates the shortest path tree from a single source node, by keep adding the nodes greedily such that at every point each node in the ...

Question 144. Check if a given array can represent Preorder Traversal of Binary Search Tree The problem “Check if a given array can represent Preorder Traversal of Binary Search Tree” states that you are given a preorder traversal sequence. Now consider this sequence and find out if this sequence can represent a binary search tree or not? The expected time complexity for the solution is ...

Question 145. Find Index of Closing Bracket for a Given Opening Bracket in an Expression Problem Statement   Given a string s of length/size n and an integer value representing the index of an opening square bracket. Find index of closing bracket for a given opening bracket in an expression. Example   s = "[ABC]" index = 0 8 s = "[C-[D]]" index = 3 5 s ...

Question 146. Design a stack that supports getMin() in O(1) time and O(1) extra space Design a stack that supports getMin() in O(1) time and O(1) extra space. Thus the special stack data structure must support all the operations of the stack like – void push() int pop() bool isFull() bool isEmpty() in constant time. Add an additional operation getMin() to return the minimum value ...

Question 147. Remove brackets from an algebraic string containing + and – operators Problem Statement   You are given a string s of size n representing an arithmetic expression with parenthesis. The problem “Remove brackets from an algebraic string containing + and – operators” asks us to create a function that can simplify the given expression. Example   s = "a-(b+c)" a-b-c  s = a-(b-c-(d+e))-f a-b+c+d+e-f ...

Question 148. Iterative Postorder Traversal Using Two Stacks Problem Statement   The problem “Iterative Postorder Traversal Using Two Stacks” states that you are given a binary tree with n nodes. Write the program for it’s iterative postorder traversal using two stacks. Example   Input   Please click Like if you loved this article? 4 5 2 6 7 3 1 ...

Question 149. Iterative method to find ancestors of a given binary tree Problem Statement   “Iterative method to find ancestors of a given binary tree” problem states that you are given a binary tree and an integer representing a key. Create a function to print all the ancestors of the given key using iteration. Example   Input  key = 6 5 2 1 Explanation: ...

Question 150. Level order Traversal in Spiral Form In this problem we have given a binary tree,  print its level order traversal in a spiral form. Examples   Input Output 10 30 20 40 50 80 70 60 Naive Approach for Level order Traversal in Spiral Form   The idea is to do a normal level order traversal using a ...

Question 151. Queue using Stacks In queue using a stack problem, we have to implement the following functions of a queue using the standard functions of stack data structure, Enqueue: Add an element to the end of the queue Dequeue: Remove an element from the start of the queue Example   Input: Enqueue(5) Enqueue(11) Enqueue(39) Dequeue()  ...

Question 152. Trapping Rain Water In Trapping Rain Water problem we have given N non-negative integers representing an elevation map and the width of each bar is 1. We have to find the amount of water that can be trapped in the above structure. Example   Let’s understand that by an example For the above elevation ...

Question 153. Binary Tree zigzag level order Traversal Given a binary tree, print the zigzag level order traversal of its node values. (ie, from left to right, then right to left for the next level and alternate between). Example   consider the binary tree given below Below is the zigzag level order traversal of the above binary tree Please ...

Question 154. Implementation of Deque using Doubly Linked List Problem Statement   The problem “Implementation of Deque using Doubly Linked List” states that you need to implement the following functions of Deque or Doubly Ended Queue using a doubly linked list, insertFront(x) : Add element x at the starting of Deque insertEnd(x) : Add element x at the end of ...

Question 155. Iterative Method to find Height of Binary Tree Problem Statement   The problem “Iterative Method to find Height of Binary Tree” states that you are given a binary tree, find the height of the tree using the iterative method. Examples   Input 3 Input 4 Algorithm for Iterative Method to find Height of Binary Tree   The height of a tree ...

Question 156. Check if all levels of two Binary Tree are anagrams or not Problem Statement   The problem “Check if all levels of two Binary Tree are anagrams or not” says that you are given two Binary Trees, check if all the levels of the two trees are anagrams or not. Examples   Input true Input Please click Like if you loved this article? false ...

Question 157. Queue using Stacks In queue using a stack problem, we have to implement the following functions of a queue using the standard functions of stack data structure, Enqueue: Add an element to the end of the queue Dequeue: Remove an element from the start of the queue Example   Input: Enqueue(5) Enqueue(11) Enqueue(39) Dequeue()  ...

Question 158. Binary Tree zigzag level order Traversal Given a binary tree, print the zigzag level order traversal of its node values. (ie, from left to right, then right to left for the next level and alternate between). Example   consider the binary tree given below Below is the zigzag level order traversal of the above binary tree Please ...

Question 159. Matrix Diagonal Sum Leetcode Solution Problem Statement   In Matrix Diagonal Sum problem a square matrix of integers is given. We have to calculate the sum of all the elements present at its diagonals i.e. elements at primary diagonal as well as secondary diagonal. Each element should be counted only once. Example mat = [[1,2,3], [4,5,6], ...

Question 160. Minimum time required to rot all oranges Problem Statement   The problem “Minimum time required to rot all oranges” states that you are given a 2D array, every cell has one of the three possible values 0, 1 or 2. 0 means an empty cell. 1 means a fresh orange. 2 means a rotten orange. If a rotten ...

Question 161. Maximal Square In the maximal square problem we have given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s, and return its area. Example   Input: 1 0 1 0 0 0 0 1 1 1 1 1 1 1 1 Please click Like if you ...

Question 162. Kth Largest Element in a Stream Leetcode Solution Problem Statement   In this problem, we have to design a class KthLargest() that initially has an integer k and an array of integers. We need to write a parameterized constructor for it when an integer k and array nums are passed as arguments. The class also has a function add(val) that adds ...

Question 163. Remove Linked List Elements Leetcode Solution Problem Statement   In this problem, we are given a linked list with its nodes having integer values. We need to delete some nodes from the list which have value equal to val. The problem does not require to be solved in-place but we will discuss one such approach. Example List = ...

Question 164. Hamming Distance Leetcode Solution Problem Statement   In this problem, we are given two integers, A and B, and the goal is to find the hamming distance between the given integers. The integers are greater that/equal to 0 and less than 231    Example First Integer = 5 , Second Integer = 2 3 First Integer ...

Question 165. Excel Sheet Column Title Leetcode Solution Problem Statement   In this problem a positive integer is given which represents a column number of an Excel sheet, we have to return its corresponding column title as appear in an Excel sheet. Example #1 28 "AB" #2 701 "ZY" Approach   This problem is the reverse of the problem in ...

Question 166. Combinations Leetcode Solution The problem Combinations Leetcode Solution provides us with two integers, n, and k. We are told to generate all the sequences that have k elements picked out of n elements from 1 to n. We return these sequences as an array. Let us go through a few examples to get ...

Question 167. Jewels and Stones Leetcode Solution The problem Jewels and Stones Leetcode Solution states that you are given two strings. One of them represents jewels and one of them represents stones. The string that contains jewels represents the characters that are jewels. We need to find the number of characters in the stones string that are ...

Question 168. Palindrome Linked List Leetcode Solution In the problem “Palindrome Linked List”, we have to check whether a given singly integer linked list is a palindrome or not. Example   List = {1 -> 2 -> 3 -> 2 -> 1} true Explanation #1: The list is palindrome as all elements from the start and back are ...

Question 169. Maximum Depth of Binary Tree Leetcode Solution Problem Statement   In the problem a binary tree is given and we have to find out the maximum depth of the given tree. A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Example 3 / ...

Question 170. Rotate List Leetcode Solution The problem Rotate List Leetcode Solution provides us a linked list and an integer. We are told to rotate the linked list to the right by k places. So if we rotate a linked list k places to the right, in each step we take the last element from the ...

Question 171. Pow(x, n) Leetcode Solution The problem “Pow(x, n) Leetcode Solution” states that you are given two numbers, one of which is a floating-point number and another an integer. The integer denotes the exponent and the base is the floating-point number. We are told to find the value after evaluating the exponent over the base. ...

Question 172. Find the Difference Leetcode Solution Problem statement   In the problem “Find the Difference” we are given two strings s and t. String t is produced by randomly stuffing the characters of string s and adding one character at a random position. our task is to find out the character which was added in string t. ...

Question 173. Merge Two Sorted Lists Leetcode Solutions Linked lists are quite like arrays in their linear properties. We can merge two sorted arrays to form an overall sorted array. In this problem, we have to merge two sorted linked lists in place to return a new list which contains elements of both lists in a sorted fashion. Example   ...

Question 174. Permutations Leetcode Solution The problem Permutations Leetcode Solution provides a simple sequence of integers and asks us to return a complete vector or array of all the permutations of the given sequence. So, before going into solving the problem. We should be familiar with permutations. So, a permutation is nothing but an arrangement ...

Question 175. House Robber II Leetcode Solution In the “House Robber II” problem, a robber wants to rob money from different houses. The amount of money in the houses is represented through an array. We need to find the maximum sum of money that can be made by adding the elements in a given array according to ...

Question 176. Convert Sorted Array to Binary Search Tree Leetcode Solution Consider we are given a sorted array of integers. The goal is to build a Binary Search Tree from this array such that the tree is height-balanced. Note that a tree is said to be height-balanced if the height difference of left and right subtrees of any node in the ...

Question 177. Sort Integers by The Number of 1 Bit Leetcode Solution Problem statement   In the problem ” Sort Integers by The Number of 1 Bit,” we are given an array arr. Our task is to sort the elements in the array according to the number of 1 bit in the binary representation of the number in ascending order. If two or ...

Question 178. Happy Number Leetcode Solution Problem Statement   The problem is to check whether a number is happy number or not. A number is said to be happy number if replacing the number by the sum of the squares of its digits, and repeating the process makes the number equal to 1. if it does not ...

Question 179. Best Time to Buy and Sell Stock with Cooldown Leetcode Solution Problem statement   In the problem “Best Time to Buy and Sell Stock with Cooldown” we are given an array where each element in the array contains the price of the given stock on that day. There is no restriction on the number of transactions. The definition of the transaction is ...

Question 180. Delete Nth node from the end of the given linked list Problem Statement   The problem “Delete Nth node from the end of the given linked list”  states that you are given a linked list with some nodes. And now you need to remove nth node from the end of the linked list. Example   2->3->4->5->6->7 delete 3rd node from last 2->3->4->6->7 Explanation: ...

Question 181. Happy Number Problem Statement   What is a happy number? A number is a happy number if we can reduce a given number to 1 following this process: -> Find the sum of the square of the digits of the given number. Replace this sum with the old number. We will repeat this ...

Question 182. Palindrome Number Problem Statement   the problem “Palindrome Number” states that you are given an integer number. Check if it is a palindrome or not. Solve this problem without converting the given number into a string. Example   12321 true Explanation 12321 is a palindrome number because when we reverse 12321 it gives 12321 ...

Question 183. Count pairs from two linked lists whose sum is equal to a given value Problem Statement   Problem “Count pairs from two linked lists whose sum is equal to a given value” state that you are given two linked lists and an integer value sum. The problem statement asked to find out how many total pair has a sum equal to the given value. Example   ...

Question 184. Minimum number of jumps to reach end Problem Statement   Suppose you have an array of integers and each element of an array indicates each number as maximum jumps that can be taken from that point. Your task is to find out the minimum number of jumps to reach end, i.e. minimum of jumps that can be taken ...

Question 185. Longest Increasing Subsequence We are provided with an array of integers that is unsorted and we have to find the longest increasing subsequence. The subsequence need not be consecutive The subsequence shall be increasing Let’s understand that better by a few examples. Example   Input [9, 2, 5, 3, 7, 10, 8] Output Please ...

Question 186. K-th Distinct Element in an Array You are given an integer array A, print k-th distinct element in an array. The given array may contain duplicates and the output should print k-th distinct element among all unique elements in an array. If k is more than a number of distinct elements, then report it. Example   Input: ...

Question 187. Merge K Sorted Linked Lists Merge K sorted linked lists problem is so famous as per the interview point of view. This question asks so many times in big companies like Google, Microsoft, Amazon, etc.  As the name suggests we’ve been provided with k sorted linked lists. We have to merge them together into a ...

Question 188. Merge Two Sorted Linked Lists In merge two sorted linked lists we have given head pointer of two linked lists, merge them such that a single linked list is obtained which has nodes with values in sorted order. return the head pointer of the merged linked list. Note: merge the linked list in-place without using ...

Question 189. Word Break Word Break is a problem that beautifully illustrates a whole new concept. We have all heard of compound words. Words made up of more than two words. Today we have a list of words and all we’ve got to do is check if all the words from the dictionary can ...

Question 190. Number Of 1 bits We have all heard of the Hamming Weight of a binary number. Hamming weight is the number of set bits/1s in a binary number. In this problem Number Of 1 bits we have to find the hamming weight of the given number. Examples Number = 3 Binary representation = 011 ...

Question 191. Merge Two Sorted Lists Leetcode What is merge two sorted lists problem on leetcode?   This is so interesting question asked so many times in compnies like Amazon, Oracle, Microsoft, etc. In this problem(Merge Two Sorted Lists Leetcode), we have given two linked lists. Both linked lists are in increasing order. Merge both linked list in ...

Question 192. Reverse Nodes in K-Group Problem   In Reverse Nodes in K-Group problem we have given a linked list, Reverse the linked list in a group of k and return the modified list. If the nodes are not multiple of k then reverse the remaining nodes. The value of k is always smaller or equal to ...

Question 193. Stone Game LeetCode What is Stone Game problem?   Stone Game LeetCode – Two players A and B are playing a stone game. There are even numbers of piles each pile containing some stones and the total stones in all the piles is odd. A and B are supposed to pick a pile either ...

Question 194. LRU Cache Implementation Least Recently Used (LRU) Cache is a type of method which is used to maintain the data such that the time required to use the data is the minimum possible. LRU algorithm used when the cache is full. We remove the least recently used data from the cache memory of ...

Question 195. Climbing stairs Problem Statement   The problem “Climbing stairs” states that you are given a staircase with n stairs. At a time you can either climb one stair or two stairs. How many numbers of ways to reach the top of the staircase? Example   3 3 Explanation There are three ways to climb ...

Question 196. Self Dividing Numbers A number is known as a self dividing numbers if – 1. Mod of every digit of number with number is zero. 2. The number should contain all non zero digits. For instance – 128 128 % 1 = 0, 128 % 2 = 0, 128 % 8 = 0 ...

Question 197. Reverse a linked list Problem Statement   The problem “reverse a linked list” states that we are given the head of the linked list. We have to reverse the linked list by changing the links between them and return the head of the reversed linked list. Example   10->20->30->40->NULL NULL<-10<-20<-30<-40 Explanation We have reversed the linked ...

Question 198. Find Nth Node Problem Statement   In the “Find Nth Node” problem we have given a linked list to find the nth node. The program should print the data value in the nth node. N is the input integer index. Example   3 1 2 3 4 5 6 3 Approach   Given a linked list ...

Question 199. Delete Last Occurrence Problem Statement   In the “Delete Last Occurrence” problem we have given a linked list. Write a program to delete the last occurrence of a given key from the linked list. The list can contain duplicates. Example   1 2 3 5 2 10 1 2 3 5 2 Approach   Given a ...