# eBay Interview Questions  Belzabar Interview Questions

## Array Questions eBay

Question 1. 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 2. Sort Array by Increasing Frequency Leetcode Solution Problem Statement   Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order. Example nums = [1,1,2,2,2,3] [3,1,1,2,2,2] Explanation: ‘3’ has a frequency of 1, ‘1’ has a frequency of ...

Question 3. 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 4. 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 5. 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 6. 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 7. 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 8. Top K Frequent Elements Problem Statement   In top K frequent elements we have given an array nums[], find the k most frequently occurring elements. Examples   nums[] = {1, 1, 1, 2, 2, 3} k = 2 1 2   nums[] = {1} k = 1 1 Naive Approach for Top K Frequent Elements   Build ...

Question 9. Maximize sum of consecutive differences in a circular array Problem Statement   Suppose you have an integer array. This array should be treated as a circular array. The last value of an array will be connected to the first array, an ⇒ a1. The problem “Maximize sum of consecutive differences in a circular array” asks to find out the maximum ...

Question 10. Find a sorted subsequence of size 3 in linear time Problem Statement   The problem “Find a sorted subsequence of size 3 in linear time” states that you have an integer array. The problem statement asks to find out the three numbers in such a way that array[i] < array [k] < array[k], and i < j < k. Example   arr[] ...

Question 11. Program for Bridge and Torch problem Problem Statement   The “Bridge and Torch” problem states that you are given an array of time a person needs to cross the bridge. Since it is time, it comprises positive integers. Along with the time we are given a bridge, which a person needs to cross. The bridge allows only ...

Question 12. 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 13. 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 14. 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 15. 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 16. 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 17. Sort Colors Sort colors is a problem in which we have to given an array containing N objects. Each box is painted with a single color which can be red, blue, and white. We have N objects which are already painted. We have to sort the array such that the same color ...

Question 18. 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 19. 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 20. 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 21. 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 22. 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 23. 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 24. 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 25. 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 26. 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 27. 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 28. 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 29. 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 30. 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 31. 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 32. 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 33. 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 34. 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 35. 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 ...

## String Questions eBay

Question 36. Letter Combinations of a Phone Number In letter combinations of a phone number problem, we have given a string containing numbers from 2 to 9. The problem is to find all the possible combinations that could be represented by that number if every number has some letters assigned to it. The assignment of the number is ...

Question 37. 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 38. Palindrome Substring Queries Problem Statement   The problem “Palindrome Substring Queries” states that you are given a String and some queries. With those queries, you have to determine if the formed substring from that query is a palindrome or not. Example   String str = "aaabbabbaaa" Queries q[] = { {2, 3}, {2, 8},{5, 7}, ...

Question 39. Decode String Suppose, you are given an encoded string. A string is encoded in some kind of pattern, your task is to decode the string. Let us say, < no of times string occurs > [string ] Example   Input 3[b]2[bc] Output Please click Like if you loved this article? bbbcaca Explanation Here ...

Question 40. Longest Common Subsequence You are given two strings str1 and str2, find out the length of the longest common subsequence. Subsequence: a subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. For ex ‘tticp‘ is the subsequence ...

Question 41. 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 42. 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 43. Reorganize String In Reorganize String problem we have given a string containing some characters “a-z” only. Our task is to rearrange those characters such that no two same characters are adjacent to each other. Example   Input apple Output pelpa Please click Like if you loved this article? Input book Output obko Input ...

Question 44. 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 45. 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 46. 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 47. Permutations of a Given String Using STL Problem Statement   In the “Permutations of a Given String Using STL” problem, we have given a string “s”. Print all the permutations of the input string using STL functions. Input Format   The first and only one line containing a string “s”. Output Format   Print all the permutation of the given ...

Question 48. 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 49. 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 ...

## Tree Questions eBay

Question 50. 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 51. 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 52. 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" ...

## Stack Questions eBay

Question 53. Decode String Suppose, you are given an encoded string. A string is encoded in some kind of pattern, your task is to decode the string. Let us say, < no of times string occurs > [string ] Example   Input 3[b]2[bc] Output Please click Like if you loved this article? bbbcaca Explanation Here ...

Question 54. 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 ...

## Queue Questions eBay

Question 55. 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 ...

## Matrix Questions eBay

Question 56. Word Search Leetcode Solution Problem Statement   Given an m x n board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where “adjacent” cells are horizontally or vertically neighbouring. The same letter cell may not be used more than once. Example ...

## Other Questions eBay

Question 57. 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 58. 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 59. 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 60. 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 61. 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 62. Leetcode Permutations In this leetcode problem premutation we have given an array of distinct integers, print all of its possible permutations. Examples   Input arr[] = {1, 2, 3} Output 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 Input arr[] = {1, 2, ...

Question 63. 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 64. 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 65. 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 66. Serialize and Deserialize Binary Tree We have given a binary tree containing N number of nodes where each node has some value. We need to serialize and deserialize the binary tree. Serialize The process of storing a tree in a file without disturbing its structure is called serialization. DeserializeSerialize and Deserialize Binary Tree The process ...