Skip to main content

Posts

Showing posts with the label PayU

Next larger element [EASY]

Company: Snapdeal, Samsung, PayU, Informatica, CouponDunia, Amazon  Question:  Given an array A [ ] having distinct elements, the task is to find the next greater element for each element of the array in order of their appearance in the array. If no such element exists, output -1  Input: The first line of input contains a single integer  T  denoting the number of test cases.Then  T  test cases follow. Each test case consists of two lines. The first line contains an integer N denoting the size of the array. The Second line of each test case contains N space separated positive integers denoting the values/elements in the array A[ ].   Output: For each test case, print in a new line, the next greater element for each array element separated by space in order. Constraints: 1<=T<=200 1<=N<=1000 1<=A[i]<=1000 Example: Input 1 4 1 3 2 4  Output 3 4 4 -1 Explanation In the array, the next larger ...

Level order traversal in spiral form [EASY]

Company: Microsoft, Housing.com, Hike, Flipkart, Amazon, Adobe, Accolite, Teradata, PayU, Ola-Cabs Question:  Write a function to print spiral order traversal of a tree. For below tree, function should print 1, 2, 3, 4, 5, 6, 7.     Input: The task is to complete the method which takes one argument, root of the Tree. The struct node has a data part which stores the data, pointer to left child and pointer to right child. There are multiple test cases. For each test case, this method will be called individually. Output: The function should print level order traversal in spiral form . Constraints: 1 <=T<= 30 1 <=Number of nodes<= 3000 1 <=Data of a node<= 1000 Example: Input: 2 2 1 2 R 1 3 L 4 10 20 L 10 30 R 20 40 L 20 60 R Output: 1 3 2 10 20 30 60 40 There are two test cases.  First case represents a tree with 3 nodes and 2 edges where root is 1, left child of 1 is 3 and right child of 1 is 2.   Second test case repr...

Leaders in Array [BASIC]

Write a program to print all the LEADERS in the array. An element is leader if it is greater than all the elements to its right side. The rightmost element is always a leader. COMPANY:PayU   Input: The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the size of array. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array. Output: Print all the leaders. Constraints: 1 <= T <= 100 1 <= N <= 100 0 <= A[i]<=100 Example: Input: 2 6 16 17 4 3 5 2 5 1 2 3 4 0 Output: 17 5 2 4 0 CODE: import java.util.*; import java.lang.*; import java.io.*; class Solution { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int m = sc.nextInt(); for(int mi=0;mi<m;mi++){    int n=sc.nextInt();    int [] ar=...

Trapping Rain water [MEDIUM]

Company: PayU, Microsoft, De-Shaw, Amazon, Accolite Question: Given n non-negative integers in array representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example: Input: 3 2 0 2 Output: 2 Structure is like below |  | |_| We can trap 2 units of water in the middle gap. Below is another example. Input: The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows. Each test case contains an integer N followed by N numbers to be stored in array. Output: Print trap units of water in the middle gap. Constraints: 1<=T<=100 3<=N<=100 0<=Arr[i]<10 Example: Input: 2 4 7 4 0 9 3 6 9 9 Output: 10  0   Code: import java.util.*; import java.lang.*; import java.io.*; class Solution { public static void main (String[] args) { Scanner sc = new Scanner(System.in);     int m = sc.nextInt(); ...

Kadane Algorithm- Longest contiguous sub-array with maximum sum [MEDIUM]

Asked in : Metlife, Housing.com ,Hike, Flipkart, FactSet, D-E Shaw ,Amazon,Accolite, Snapdeal, Samsung ,PayU , Paytm ,Oracle, Ola,Microsoft, Morgan Stanley Question: Given an array containing both negative and positive integers. Find the contiguous sub-array with maximum sum. Input: The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the size of array. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array. Output: Print the maximum sum of the contiguous sub-array in a separate line for each test case. Constraints: 1 ≤ T ≤ 200 1 ≤ N ≤ 100 -100 ≤ A[i] <= 100 Example: Input 2 3 1 2 3 4 -1 -2 -3 -4 Output 6 -1 Code: import java.io.*; // Java program to print largest contiguous array sum import java.util.*; class Solution {     public static void main (Strin...