Add office photos
CodeNation logo
Employer?
Claim Account for FREE

CodeNation

3.7
based on 5 Reviews
Filter interviews by
Designation
Fresher

CodeNation Interview Questions and Answers

Updated 5 Feb 2024

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

Ans.

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.

Add your answer
right arrow

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

Ans.

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

Add your answer
right arrow
CodeNation Interview Questions and Answers for Freshers
illustration image

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

Ans.

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.

Add your answer
right arrow

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

Ans.

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.

Add your answer
right arrow
Discover CodeNation interview dos and don'ts from real experiences

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

Ans.

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.

Add your answer
right arrow

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

Ans.

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

Add your answer
right arrow

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

Ans.

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.

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

Top Interview Questions from Similar Companies

LTIMindtree Logo
3.8
 • 2k Interview Questions
Deloitte Logo
3.8
 • 1.7k Interview Questions
Mphasis Logo
3.4
 • 527 Interview Questions
HCL Group Logo
3.6
 • 262 Interview Questions
Intas Pharmaceuticals Logo
4.1
 • 162 Interview Questions
Bosch Logo
4.2
 • 151 Interview Questions
View all
Recently Viewed
INTERVIEWS
Experian
No Interviews
INTERVIEWS
Aurus
No Interviews
INTERVIEWS
Ice Creative Excellence
No Interviews
INTERVIEWS
Aurus
No Interviews
INTERVIEWS
Smart Chip
No Interviews
INTERVIEWS
Uni Cards
10 top interview questions
INTERVIEWS
Aurus
No Interviews
LIST OF COMPANIES
Smart Chip
Locations
INTERVIEWS
Aurus
No Interviews
INTERVIEWS
Experian
No Interviews
Top CodeNation Interview Questions And Answers
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
75 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