Add office photos
Engaged Employer

UBS

3.9
based on 2.8k Reviews
Video summary
Filter interviews by

Genpact Interview Questions and Answers

Updated 5 Feb 2024
Popular Designations

Q1. String Transformation Problem

Given a string (STR) of length N, you are tasked to create a new string through the following method:

Select the smallest character from the first K characters of STR, remove it fr...read more

Ans.

Given a string and an integer, create a new string by selecting the smallest character from the first K characters of the input string and repeating the process until the input string is empty.

  • Iterate through the input string, selecting the smallest character from the first K characters each time.

  • Remove the selected character from the input string and append it to the new string.

  • Continue this process until the input string is empty.

  • Return the final new string formed.

Add your answer

Q2. Merge K Sorted Arrays Problem Statement

Given 'K' different arrays that are individually sorted in ascending order, merge all these arrays into a single array that is also sorted in ascending order.

Input

The f...read more
Ans.

Merge K sorted arrays into a single sorted array.

  • Create a min heap to store the first element of each array along with the array index.

  • Pop the top element from the heap, add it to the result array, and push the next element from the same array back to the heap.

  • Continue this process until all elements are processed.

  • Time complexity can be optimized using a priority queue or merge sort technique.

Add your answer

Q3. Sort 0 1 2 Problem Statement

Given an integer array arr of size 'N' containing only 0s, 1s, and 2s, write an algorithm to sort the array.

Input:

The first line contains an integer 'T' representing the number of...read more
Ans.

Sort an array of 0s, 1s, and 2s in linear time complexity.

  • Use three pointers to keep track of 0s, 1s, and 2s while iterating through the array.

  • Swap elements based on the values encountered to sort the array in-place.

  • Ensure to handle edge cases like all 0s, all 1s, and all 2s in the array.

Add your answer

Q4. Find Maximum Number by At-most K Swaps

Given an array of non-negative integers representing the digits of a number and an integer 'K', calculate the maximum possible number by swapping its digits up to 'K' time...read more

Ans.

Given an array of digits and an integer K, find the maximum number by swapping digits up to K times.

  • Sort the digits in non-increasing order to maximize the number.

  • Swap the digits to achieve the maximum number within the given number of swaps.

  • Handle cases where there are repeating digits and leading zeros.

Add your answer
Discover Genpact interview dos and don'ts from real experiences

Q5. Move Zeroes to End Problem Statement

Given an unsorted array of integers, modify the array such that all the zeroes are moved to the end, while maintaining the order of non-zero elements as they appear original...read more

Ans.

Move all zeroes to the end of an unsorted array while maintaining the order of non-zero elements.

  • Iterate through the array and keep track of the index to place non-zero elements.

  • Once all non-zero elements are placed, fill the rest of the array with zeroes.

  • Ensure to maintain the relative order of non-zero elements.

  • Example: Input: [0, 1, -2, 3, 4, 0, 5, -27, 9, 0], Output: [1, -2, 3, 4, 5, -27, 9, 0, 0, 0]

Add your answer

Q6. BST Node Deletion Problem

Given a binary search tree (BST) and a key value K, your task is to delete the node with value K. It is guaranteed that a node with value K exists in the BST.

Explanation:

A binary sea...read more

Ans.

Delete a node with a given value from a binary search tree (BST).

  • Traverse the BST to find the node with the value K to be deleted.

  • Handle different cases like node with no children, one child, or two children.

  • Update the pointers of the parent node and child nodes accordingly.

  • Recursively delete the node and adjust the tree structure.

  • Return the root of the modified BST after deletion.

Add your answer

Q7. Preorder Traversal of a BST Problem Statement

Given an array PREORDER representing the preorder traversal of a Binary Search Tree (BST) with N nodes, construct the original BST.

Each element in the given array ...read more

Ans.

Given a preorder traversal of a BST, construct the BST and return its inorder traversal.

  • Create a binary search tree from the preorder traversal array

  • Return the inorder traversal of the constructed BST

  • Ensure each element in the array is distinct

Add your answer
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top C Developer Interview Questions from Similar Companies

3.5
 • 12 Interview Questions
View all
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter