
CodeNation

CodeNation Interview Questions and Answers
Q1. Minimum Fountains Activation Problem
In this problem, you have a one-dimensional garden of length 'N'. Each position from 0 to 'N' has a fountain that can provide water to the garden up to a certain range. Thus...read more
Find the minimum number of fountains to activate to water the entire garden.
Iterate through the array to find the coverage of each fountain.
Keep track of the farthest coverage reached by activating fountains.
Activate the fountain that covers the farthest distance to minimize the number of fountains activated.
Q2. Count Distinct Bitwise OR of All Subarrays
Given an array of positive integers, determine the number of distinct values obtained by applying the bitwise OR operation on all possible subarrays.
Explanation:
A su...read more
Count distinct values obtained by applying bitwise OR operation on all possible subarrays of an array of positive integers.
Use a set to store distinct values obtained by bitwise OR operation on all subarrays.
Iterate through all subarrays efficiently to calculate distinct values.
Optimize the solution to handle large input sizes efficiently.
Handle bitwise OR operation on subarrays using bitwise operators.
Consider using dynamic programming or sliding window technique for optimiz...read more
Q3. Count Inversions Problem Statement
Given an integer array ARR
of size N
, your task is to find the total number of inversions that exist in the array.
An inversion is defined for a pair of integers in the array ...read more
Count the total number of inversions in an integer array.
Iterate through the array and for each pair of elements, check if the inversion condition is met.
Use a nested loop to compare each pair of elements efficiently.
Keep a count of the inversions found and return the total count at the end.
Q4. Array Transformation Problem
Given an array ARR
consisting of N
integers and a non-negative integer K
. An operation on the array replaces each element ELE
with MX - ELE
, where MX
is the maximum element of the a...read more
Given an array and a non-negative integer K, perform K operations on the array by replacing each element with MX - element, where MX is the maximum element of the array.
Find the maximum element in the array.
Perform the operation on each element K times.
Update the array after each operation.
Print the transformed array elements after K operations.
Q5. Graph Coloring Problem
You are given a graph with 'N' vertices numbered from '1' to 'N' and 'M' edges. Your task is to color this graph using two colors, such as blue and red, in a way that no two adjacent vert...read more
The task is to color a graph with two colors in a way that no two adjacent vertices share the same color.
Check if the graph can be colored using two colors without any adjacent vertices sharing the same color.
Use graph coloring algorithms like BFS or DFS to solve the problem.
If there are odd cycles in the graph, it is not possible to color the graph as described.
If the graph is bipartite, then it is possible to color the graph as described.
Q6. Kth Largest Number Problem Statement
You are given a continuous stream of numbers, and the task is to determine the kth largest number at any moment during the stream.
Explanation:
A specialized data structure ...read more
Design a data structure to find the kth largest number in a continuous stream of integers.
Design a specialized data structure to handle continuous stream of numbers
Implement add(DATA) function to add integers to the pool
Implement getKthLargest() function to retrieve the kth largest number
Maintain the pool of numbers and update it based on queries
Output the kth largest number for each Type 2 query
Q7. Rat in a Maze Problem Statement
You need to determine all possible paths for a rat starting at position (0, 0) in a square maze to reach its destination at (N-1, N-1). The maze is represented as an N*N matrix w...read more
Find all possible paths for a rat in a maze from source to destination.
Use backtracking to explore all possible paths in the maze.
Keep track of visited cells to avoid revisiting them.
Recursively try moving in all directions (up, down, left, right) until reaching the destination.
Add the valid path to the result list when the destination is reached.
Sort the result list in alphabetical order before returning.

Top Interview Questions from Similar Companies








Reviews
Interviews
Salaries
Users/Month

