Nagarro
100+ Google Interview Questions and Answers
Q1. Crazy Numbers Pattern Challenge
Ninja enjoys arranging numbers in a sequence. He plans to arrange them in 'N' rows such that:
- The first row contains 1 number.
- The second row contains 2 numbers.
- The third row c...read more
Q2. String Compression Problem Statement
Ninja needs to perform basic string compression. For any character that repeats consecutively more than once, replace the repeated sequence with the character followed by th...read more
Q3. Ninja and the New Year Guests Problem
Ninja has organized a new year party and wants to verify if the guests are programmers by challenging them with a coding task. As an invited programmer, you're tasked to so...read more
Q4. Maximum Subarray Sum Problem Statement
Given an array arr
of length N
consisting of integers, find the sum of the subarray (including empty subarray) with the maximum sum among all subarrays.
Explanation:
A sub...read more
Q5. Maximum Meetings Problem Statement
Given the schedule of N meetings with their start time Start[i]
and end time End[i]
, you need to determine which meetings can be organized in a single meeting room such that t...read more
Q6. Ways To Make Coin Change
Given an infinite supply of coins of varying denominations, determine the total number of ways to make change for a specified value using these coins. If it's not possible to make the c...read more
Q7. Fibonacci Membership Check
Given an integer N
, determine if it is a member of the Fibonacci series. Return true
if the number is a member of the Fibonacci series, otherwise return false
.
Fibonacci Series Defini...read more
Q8. Longest Increasing Subsequence Problem Statement
Given an array of integers with 'N' elements, determine the length of the longest subsequence where each element is greater than the previous element. This subse...read more
Q9. Next Permutation Problem Statement
You are given a permutation of 'N' integers. A sequence of 'N' integers is considered a permutation if it includes all integers from 1 to 'N' exactly once. Your task is to rea...read more
Q10. Coin Game Winner Problem Statement
Two players 'X' and 'Y' are participating in a coin game. Starting with 'N' coins, players alternate turns, with 'X' starting first. On each turn, a player has three choices: ...read more
Q11. Problem: Sort an Array of 0s, 1s, and 2s
Given an array/list ARR
consisting of integers where each element is either 0, 1, or 2, your task is to sort this array in increasing order.
Input:
The input starts with...read more
Q12. Find Duplicates in an Array
Given an array ARR
of size 'N', where each integer is in the range from 0 to N - 1, identify all elements that appear more than once.
Return the duplicate elements in any order. If n...read more
Q13. Count Pairs with Difference K
Given an array of integers and an integer K
, determine and print the count of all pairs in the array that have an absolute difference of K
.
Input:
The first line of the input conta...read more
Q14. Trapping Rain Water Problem Statement
You are given a long type array/list ARR
of size N
, representing an elevation map. The value ARR[i]
denotes the elevation of the ith
bar. Your task is to determine the tota...read more
Q15. Count Ways to Reach the N-th Stair Problem Statement
You are provided with a number of stairs, and initially, you are located at the 0th stair. You need to reach the Nth stair, and you can climb one or two step...read more
Q16. Closest Perfect Square Problem Statement
Given a positive integer 'N', determine the perfect square number closest to 'N' and the number of steps required to reach that perfect square.
Example:
Input:
N = 21
Ou...read more
Q17. Find the Longest Palindromic Substring
Given a string ‘S’ composed of lowercase English letters, your task is to identify the longest palindromic substring within ‘S’.
If there are multiple longest palindromic ...read more
Q18. Nearest Numbers with the Same Number of Set Bits
Given a positive integer n
, your task is to determine the next smallest integer and the previous largest integer that have the same number of '1' bits in their b...read more
Q19. Missing Number Statement
Given an array ARR
of integers with size N
, where all elements appear an even number of times except for one element which appears an odd number of times, identify the element that appe...read more
Q20. Palindrome String Validation
Determine if a given string 'S' is a palindrome, considering only alphanumeric characters and ignoring spaces and symbols.
Note:
The string 'S' should be evaluated in a case-insensi...read more
Q21. Complete String Problem Statement
Given an array of strings A
of size N
, determine the longest complete string. A string is deemed complete if every prefix of the string also appears in the array. If multiple s...read more
Q22. Equilibrium Index Problem Statement
Given an array Arr
consisting of N integers, your task is to find the equilibrium index of the array.
An index is considered as an equilibrium index if the sum of elements of...read more
Q23. Valid Parentheses Problem Statement
Given a string 'STR' consisting solely of the characters “{”, “}”, “(”, “)”, “[” and “]”, determine if the parentheses are balanced.
Input:
The first line contains an integer...read more
Q24. K - Sum Path In A Binary Tree
Given a binary tree where each node contains an integer value, and a value 'K', your task is to find all the paths in the binary tree such that the sum of the node values in each p...read more
Q25. Convert Sentence Problem Statement
Convert a given string 'S' into its equivalent representation based on a mobile numeric keypad sequence. Using the keypad layout shown in the reference, output the sequence of...read more
Q26. 0/1 Knapsack Problem Statement
A thief is planning to rob a store and can carry a maximum weight 'W' in their knapsack. The store contains 'N' items, each with a known weight and value. Given these constraints,...read more
Q27. Prime Numbers Identification
Given a positive integer N
, your task is to identify all prime numbers less than or equal to N
.
Explanation:
A prime number is a natural number greater than 1 that has no positive d...read more
Q28. K Subsets with Equal Sum Problem Statement
Determine whether it is possible to partition an array ARR
into K
subsets, each having an equal sum.
Example:
Input:
ARR = [3, 5, 2, 4, 4], K = 2
Output:
true
Explanat...read more
Q29. Subsequences of String Problem Statement
You are provided with a string 'STR'
that consists of lowercase English letters ranging from 'a' to 'z'. Your task is to determine all non-empty possible subsequences of...read more
Q30. Count Derangements
Determine the number of derangements possible for a set of 'N' elements. A derangement is a permutation where no element appears in its original position.
Input:
An integer 'T' representing t...read more
Q31. Duplicate Subtrees Problem Statement
Given a binary tree, return the root values of all duplicate subtrees. Two subtrees are considered duplicate if they have the same structure with identical node values. For ...read more
Q32. Rearrange Array: Move Negative Numbers to the Beginning
Given an array ARR
consisting of N
integers, rearrange the elements such that all negative numbers are located before all positive numbers. The order of e...read more
Q33. Common Elements Problem Statement
Identify and output the common strings present in both given arrays of lowercase alphabets for each test case.
Input:
The first line contains an integer 'T' representing the nu...read more
Q34. K Sum Subset Problem Statement
Given an array arr
of size 'N' and an integer 'K', determine the maximum subset sum of the array that does not exceed 'K'.
Example:
Input:
arr = [1, 3, 5, 9], K = 16
Output:
15
Ex...read more
Q35. Pair Sum Problem Statement
You are given an integer array 'ARR' of size 'N' and an integer 'S'. Your task is to find and return a list of all pairs of elements where each sum of a pair equals 'S'.
Note:
Each pa...read more
Q36. Find All Pairs Adding Up to Target
Given an array of integers ARR
of length N
and an integer Target
, your task is to return all pairs of elements such that they add up to the Target
.
Input:
The first line conta...read more
Q37. Letter Combinations of a Phone Number Problem Statement
You are given a string S
containing digits from 2 to 9 inclusive. Your task is to find all possible letter combinations that the number could represent, b...read more
Q38. Minimum Number of Platforms Needed Problem Statement
You are given the arrival and departure times of N trains at a railway station for a particular day. Your task is to determine the minimum number of platform...read more
Q39. Spiral Order Traversal of a Binary Tree
Given a binary tree with N
nodes, your task is to output the Spiral Order traversal of the binary tree.
Input:
The input consists of a single line containing elements of ...read more
Q40. Validate BST Problem Statement
Given a binary tree with N
nodes, determine whether the tree is a Binary Search Tree (BST). If it is a BST, return true
; otherwise, return false
.
A binary search tree (BST) is a b...read more
Q41. Sort a "K" Sorted Doubly Linked List Problem Statement
You are given a doubly linked list with 'N' nodes, where each node can deviate at most 'K' positions from its actual position in the sorted list. Your task...read more
Q42. First Non-Repeating Character Problem Statement
You are given a string consisting of English alphabet characters. Your task is to identify and return the first character in the string that does not repeat. If e...read more
Q43. Reverse Alternate K Nodes Problem Statement
You are given a singly linked list of integers along with a positive integer 'K'. The task is to modify the linked list by reversing every alternate 'K' nodes of the ...read more
Q44. Print All Paths Problem Statement
In this problem, you are provided with a graph consisting of 'N' nodes and 'M' unidirectional edges. Additionally, two integers 'S' and 'D' are given, representing the source a...read more
Q45. Maximum Path Sum Between Two Leaves
Given a non-empty binary tree where each node has a non-negative integer value, determine the maximum possible sum of the path between any two leaves of the given tree.
Expla...read more
Q46. Stock Trading Maximum Profit Problem
Given the stock prices for 'N' days, your goal is to determine the maximum profit that can be achieved. You can buy and sell the stocks any number of times but can only hold...read more
Q47. Rotational Equivalence of Strings Problem Statement
Given two strings 'P' and 'Q' of equal length, determine if string 'P' can be transformed into string 'Q' by cyclically rotating it to the right any number of...read more
Q48. Merge k Sorted Linked Lists
You are provided with 'K' sorted linked lists, each sorted in increasing order. Your task is to merge all these lists into one single sorted linked list and return the head of the re...read more
Q49. Zigzag Binary Tree Traversal Problem
Given a binary tree, compute the zigzag level order traversal of the node values in the tree. The zigzag traversal requires traversing levels from left to right, then right ...read more
Q50. Number of Islands Problem Statement
You are provided with a 2-dimensional matrix having N
rows and M
columns, containing only 1s (land) and 0s (water). Your goal is to determine the number of islands in this ma...read more
Q51. Most Frequent Word Problem Statement
You are given two strings 'A' and 'B' composed of words separated by spaces. Your task is to determine the most frequent and lexicographically smallest word in string 'A' th...read more
Q52. Count Derangements Problem Statement
You are tasked with finding the total number of derangements for a given set of elements. Specifically, for an integer N
, determine how many ways there are to permute a set ...read more
Q53. Merge Sort Linked List Problem Statement
You are given a singly linked list of integers. Your task is to sort the linked list using the merge sort algorithm.
Explanation:
Merge Sort is a divide and conquer algo...read more
Q54. Minimum Steps for a Knight to Reach Target
Given a square chessboard of size N x N
, you need to determine the minimum number of steps a Knight takes to reach a target position from its starting position.
Input:...read more
Q55. Code Optimization Problem
Ninja encountered an issue with a practice problem where certain test cases could not be passed due to high time complexity. You are provided with a snippet of pseudocode, and your tas...read more
Q56. Binary Palindrome Check
Given an integer N
, determine whether its binary representation is a palindrome.
Input:
The first line contains an integer 'T' representing the number of test cases.
The next 'T' lines e...read more
Q57. Height of Binary Tree
You are provided with the Inorder and Level Order traversals of a Binary Tree composed of integers. Your goal is to determine the height of this Binary Tree without actually constructing i...read more
Q58. Factorial Calculation Problem Statement
Develop a program to compute the factorial of a given integer 'n'.
The factorial of a non-negative integer 'n', denoted as n!
, is the product of all positive integers les...read more
Q59. Difference between High severity and low severity with example, what is important as QA point of view?
High severity refers to critical defects that impact the core functionality of the software, while low severity refers to minor issues that have minimal impact on functionality.
High severity issues can cause the software to crash or result in data loss.
Low severity issues are cosmetic or minor usability problems.
From a QA point of view, high severity issues are more critical as they can significantly impact the user experience and the overall functionality of the software.
Low...read more
Q62. Make a 3*3 cube where you need to fill the numbers using 1-9, rows, columns and diagonal sum should be equal to 15
Create a 3x3 cube with numbers 1-9, where the sum of rows, columns, and diagonals is 15.
Start with the number 5 in the center of the cube.
Place the numbers 1 and 9 in the corners.
Fill the remaining numbers in a way that each row, column, and diagonal adds up to 15.
Q64. An array contain 6 different numbers, only 1 number is repeated for 5 times. So now total 10 numbers in array, Find that duplicate number in 2 steps only?
Find the duplicate number in an array of 10 numbers with only 2 steps.
Use a hash set to keep track of visited numbers.
Iterate through the array and check if the number is already in the set.
If it is, then it is the duplicate number.
If not, add it to the set.
At the end, the duplicate number will be found.
Q65. Input an array and then print the repeating characters?? Example: Input:1,3,23,11,44,3,23,2,3. Output:3,23
The question asks to input an array and print the repeating characters.
Iterate through the array and store each element in a hash table or dictionary.
If an element already exists in the hash table, it is a repeating character.
Print all the repeating characters found.
Q66. What are the different access modifiers and what is there uses?
Access modifiers control the visibility and accessibility of class members.
Public: accessible from anywhere
Private: accessible only within the class
Protected: accessible within the class and its subclasses
Default: accessible within the same package
Used to enforce encapsulation and prevent unauthorized access
Q67. Input a number and then find the next higher number such that for both the number (inputted and the next higher number) in binary representation contains equal number os ones. Example: Input:3(0000000000000011)...
read moreFind the next higher number with equal number of ones in binary representation.
Convert input number to binary
Count number of ones in binary representation
Increment input number until binary representation has equal number of ones
Convert incremented number to decimal
Q68. Input an array and prints the second minimum in an array?? Example Input:34,45,21,12,54,67,15 Output:15
Program to find the second minimum in an array.
Sort the array and return the second element.
Initialize two variables to store minimum and second minimum values.
Loop through the array and update the variables accordingly.
Q69. Write a program to print elements of a linked list in reverse order by using same single linked list?
Program to print elements of a linked list in reverse order using same single linked list
Traverse the linked list and push each element onto a stack
Pop elements from the stack and print them in reverse order
Q71. Take an array, store the numbers and print the numbers using arrayList?
To store and print numbers from an array using arrayList.
Create an arrayList object
Loop through the array and add each element to the arrayList using add() method
Print the arrayList using toString() method
Example: int[] arr = {1, 2, 3}; ArrayList
list = new ArrayList<>(); for(int num : arr) { list.add(num); } System.out.println(list.toString());
Q72. Clone a FULL linked list given a pointer and a random pointer
Clone a linked list with a random pointer.
Create a new node for each node in the original list.
Use a hash table to map the original nodes to their clones.
Iterate through the original list again and update the random pointers of the clone nodes.
Q75. What is a binary tree and implementation? what is the heap? Array and sorting? Coding Problem.
Binary tree is a data structure where each node has at most two children. Heap is a specialized tree-based data structure. Array is a collection of elements stored in contiguous memory locations.
Binary tree can be implemented using linked lists or arrays.
Heap is used to efficiently implement priority queues.
Sorting algorithms like bubble sort, insertion sort, merge sort, quick sort can be used to sort arrays.
Coding problem can be related to traversing a binary tree, implement...read more
Q76. How and when API controller class instance generated in c#
API controller class instance is generated when a request is made to the API endpoint.
API controller class is responsible for handling incoming requests and returning responses.
Instance of API controller class is generated by the ASP.NET Core framework when a request is made to the API endpoint.
API controller class instance is disposed of after the request has been processed.
API controller class can be customized and configured using attributes and middleware.
Q77. Write a program for given login scenario using defined automation architecture?
A program for login scenario using defined automation architecture.
Identify the elements on the login page such as username, password, and login button
Use automation tools like Selenium to interact with the elements and input data
Verify successful login by checking for expected elements on the landing page
Implement error handling for incorrect login credentials
Use a modular and scalable architecture for maintainability
Q78. What is constructor and destructor and also explain its working
Constructor and destructor are special member functions in a class that are used to initialize and destroy objects respectively.
Constructor is called when an object is created and is used to initialize the object's data members.
Destructor is called when an object is destroyed and is used to free up any resources that the object was using.
Constructor has the same name as the class and no return type, while destructor has the same name as the class preceded by a tilde (~) and n...read more
Q79. Write test scenario for download functionality of a songs website?
Test scenario for download functionality of a songs website
Verify that the download button is visible and clickable
Check that the downloaded file is in the correct format
Ensure that the downloaded file is not corrupted
Test the download speed for different file sizes
Verify that the download progress is displayed to the user
Q80. Find the longest palendrom in a string? Example Input: abfgerccdedccfgfer Output: ccdedcc
To find the longest palindrome in a given string.
Iterate through the string and check for palindromes of odd and even lengths.
Keep track of the longest palindrome found so far.
Use two pointers to check if the substring is a palindrome.
If the substring is a palindrome and its length is greater than the current longest palindrome, update the longest palindrome.
Q82. What is polymorphism and explain in brief?
Polymorphism is the ability of an object to take on many forms.
Polymorphism allows objects of different classes to be treated as if they are of the same class.
It is achieved through method overriding and method overloading.
Example: A parent class Animal can have child classes like Dog, Cat, and Cow. All these child classes can have a method called 'makeSound', but each class can have a different implementation of the method.
Polymorphism makes code more flexible and reusable.
Q84. Reverse a linked list (iterative AND Recursive)
Reverse a linked list using iterative and recursive methods.
Iterative method involves traversing the list and changing the pointers to reverse the order.
Recursive method involves calling the function recursively on the next node and changing the pointers.
Both methods have O(n) time complexity and O(1) space complexity.
Example: 1->2->3->4->5 becomes 5->4->3->2->1.
Q85. what is theConcept of oops language
OOPs is a programming paradigm based on the concept of objects, which can contain data and code.
OOPs stands for Object-Oriented Programming.
It focuses on creating objects that interact with each other to solve a problem.
It uses concepts like inheritance, encapsulation, and polymorphism.
Inheritance allows a class to inherit properties and methods from another class.
Encapsulation is the practice of hiding data and methods within a class.
Polymorphism allows objects to take on mu...read more
Q86. Difference between interface and abstract?
Interface defines only method signatures while abstract class can have both method signatures and implementations.
An interface can be implemented by multiple classes while an abstract class can only be extended by one class.
An abstract class can have constructors while an interface cannot.
An abstract class can have instance variables while an interface cannot.
An abstract class can provide default implementations for some methods while an interface cannot.
An abstract class can...read more
Q87. What is static keyword?
Static keyword is used to declare a variable or method that belongs to the class rather than an instance of the class.
Static variables are shared among all instances of a class
Static methods can be called without creating an instance of the class
Static blocks are used to initialize static variables
Static keyword can also be used to create nested classes
Example: public static int count;
Q88. Output of coding example based on interval functions in javascript
Output of interval functions in JavaScript
Interval functions are used to execute a block of code repeatedly at a specified time interval
The output of the coding example will depend on the specific implementation of the interval function
Common interval functions in JavaScript include setInterval() and setTimeout()
Q89. Difference between cache and cookies?
Cache stores data temporarily to reduce server load while cookies store user information for website personalization.
Cache stores frequently accessed data to reduce server load and improve website performance.
Cookies store user information such as login credentials, preferences, and shopping cart items.
Cache is temporary and can be cleared at any time, while cookies can have an expiration date.
Cache is stored on the user's device, while cookies are stored on the server.
Exampl...read more
Q90. Introduction Mind checking Ready to relocate?
Yes, I am open to relocation for the right opportunity.
I am willing to relocate for a position that aligns with my career goals and offers growth opportunities.
I am open to considering relocation packages and assistance.
I am excited about the prospect of exploring new cities and cultures.
Examples: I have previously relocated for a job and found it to be a positive experience.
I am willing to discuss relocation during the interview process.
Q91. What is polymorphism?
Polymorphism is the ability of a single function or method to operate on different types of data.
Polymorphism allows objects of different classes to be treated as objects of a common superclass.
There are two types of polymorphism: compile-time (method overloading) and runtime (method overriding).
Example: Inheritance in object-oriented programming languages like Java allows for polymorphism.
Q92. Difference between class and interface?
Class is a blueprint for creating objects while interface defines a contract for classes to implement.
A class can have attributes and methods while an interface only has method signatures.
A class can be instantiated while an interface cannot.
A class can only inherit from one class while it can implement multiple interfaces.
Example: Class - Animal, Interface - Flyable
Animal can have attributes like name, age, etc. and methods like eat(), sleep(), etc.
Flyable interface only has...read more
Q93. Define Automation framework?
Automation framework is a set of guidelines, standards, and coding practices used to create automated test scripts.
It provides a structured way to develop and maintain automated tests
It includes tools, libraries, and reusable components
It helps in reducing the time and effort required for testing
Examples include Selenium, Appium, and Robot Framework
Q94. What is event driven architecture
Event driven architecture is a design pattern where the flow of the system is determined by events.
Events are generated by various components and can trigger actions in other components.
It allows for loosely coupled systems, as components can communicate without direct dependencies.
Common examples include message queues, pub/sub systems, and webhooks.
Q95. Dual logging in Spring Mvc architecture.
Dual logging in Spring MVC architecture involves configuring two different logging frameworks to log messages in parallel.
Configure both Logback and Log4j in the Spring MVC application
Use different log levels for each framework to control the verbosity of logs
Specify separate log files for each framework to store the log messages
Q96. What is memory segmentation?
Memory segmentation is a memory management technique where memory is divided into segments to improve efficiency and organization.
Memory segmentation divides memory into segments of different sizes for better organization.
Each segment is assigned a base address and a limit to control access.
Segments can be used to store different types of data or code, such as stack, heap, and code segments.
Segmentation can help prevent memory fragmentation and improve memory utilization.
Exam...read more
Q97. Middle of linked list
To find the middle element of a linked list, use two pointers - one moving at twice the speed of the other.
Initialize two pointers, slow and fast, at the head of the linked list.
Move slow pointer by one node and fast pointer by two nodes until fast pointer reaches the end of the list.
The node pointed to by the slow pointer at this point is the middle element of the linked list.
Q98. Interfaces in oops
Interfaces define a contract for classes to implement certain methods and properties.
Interfaces allow for polymorphism and loose coupling.
Classes can implement multiple interfaces.
Interfaces cannot be instantiated on their own.
Interfaces can have default method implementations.
Interfaces can be used to enforce design patterns like the adapter pattern.
Q99. Inheritance in java and keywords
Inheritance in Java allows a class to inherit attributes and methods from another class. Keywords like 'extends' and 'super' are used.
Inheritance allows a class to inherit attributes and methods from another class
The 'extends' keyword is used to create a subclass that inherits from a superclass
The 'super' keyword is used to access the superclass constructor or methods
Example: class Animal {} class Dog extends Animal {}
Q100. Kafka and how to implement
Kafka is a distributed streaming platform used for building real-time data pipelines and streaming applications.
Kafka is used for building real-time data pipelines and streaming applications
It provides high-throughput, fault-tolerant, and scalable messaging system
Kafka uses topics to categorize messages and consumers subscribe to topics to receive messages
Producers publish messages to topics and consumers consume messages from topics
More about working at Nagarro
Interview Process at Google
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month