Skip to main content

Posts

Showing posts with the label Grofers

Insertion Sort [EASY/IMP]

Company: Veritas, MAQ-Software, Juniper, Grofers, Dell, Cisco, Accenture Question: Perform Insertion sort CODE: /* Function to sort an array using insertion sort void insertionSort(int arr[], int n) {   GfG obj = new GfG();    for (int i = 1; i < n; i++)       obj.insert(arr, i); } */ class GfG {   // Function to sort an array using insertion sort   void insert(int arr[],int i)   {        int key=arr[i];        int j=i-1;        while (j>=0 && arr[j] > key)             {                 arr[j+1] = arr[j];                 j = j-1;             }             arr[j+1] = key;   } } EXECUTION TIME:0.4s

Implement Stack Using Queues [EASY/IMPORTANT]

Company: Grofers, DE-Shaw, CouponDunia, Amazon, Adobe, Accolite, Snapdeal, Oracle, Kritical Solutions Question: Implement a Stack using 2 queue  q1  and  q2  . Input : The first line of the input contains an integer ' T ' denoting the number of test cases. Then T test cases follow. First line of each test case contains an integer  Q  denoting the number of queries .  A Query  Q  is of 2 Types (i)  1 x   (a query of this type means  pushing  'x'  into the stack) (ii)  2     (a query of this type means to pop element from stack and print the poped element) The second line of each test case contains  Q  queries seperated by space. Output: The output for each test case will  be space separated integers having  -1  if the stack is empty else the element poped out from the stack .  You are required to...