Number in a range
You are given three integers L, R, and K. A number X represents a lucky number if the binary representation of X contains the pattern 101 as a substring. Determine the Kth lucky number between L and R. If the Kth lucky number does not exist, then print -1.
Function description
Complete the solve function. This function takes the following 3 parameters and returns the Kth
Asked in: ADOBE
You are given a board of size M ร N where each cell can be either empty ('O') or a wall ('X').
A robot is initially placed at the top-left cell (0,0) and can move in four directions: up, down, left, and right โ but not diagonally.
The robot can only move through empty cells and cannot pass through or land on walls.
Your task is to print the maximum number of empty cells the robot can vi
Asked in: FLIPKART
Undirected Coloured Graph Shortest Path
You are given an undirected weighted graph G(V, E) where each vertex is assigned a colour. Vertices form pairs of the same colour. Thus, total pairs = V/2 (if V is even) or (V/2)+1 (if V is odd). Each pair is assigned a unique colour.
A query Q specifies a colour, and your task is to find the shortest path (in terms of weight) between the two vertice
Asked in: FLIPKART
Village Voyage
A computer game "Village Voyage" has N villages (labeled 1 to N) at some distance from each other. The player starts from any village S and travels through all villages in a circular route, returning to the starting village S. Each village provides energy drinks, which are used to travel to the next village. One energy drink allows travel of one unit distance. The player loses if
Asked in: FLIPKART
Academic Decathlon
Students are being selected for an academic decathlon team at a school. Each student has a skill level, and for a team to be uniform, the difference between any two consecutive skill levels (when arranged in increasing order) must be either 0 or 1.
Your task is to find the maximum possible team size.
Example
skills = [0, 12, 13, 9, 14]
Valid teams, when sorted, ar
Asked in: UBER
Sum of Arrays
Given two arrays each of length n, arr1 and arr2, in one operation, any two elements of an array can be swapped. This can occur any number of times.
Find the maximum possible sum of i * (arr2[i] - arr1[i]) for all 1 โค i โค n after rearranging the arrays. Since the maximum possible sum can be large, return the value modulo (10^9 + 7).
Example
n = 4
arr1 = [2, 1, 3, 4]
Asked in: UBER
Count Swaps During Custom Sorting
Analyze the efficiency of the following sorting algorithm by counting the number of swaps it performs:
For an array arr of size n:
1. Find the smallest pair of indices 0 โค i < j โค n-1 such that arr[i] > arr[j], where "smallest" means lexicographical ordering of pairs (i1, j1) < (i2, j2) if i1 < i2 or (i1 = i2 and j1 < j2).
2. If no such pair exists, th
Asked in: UBER
Stacey is coordinating a beach clean-up event with her university's Women in STEM Charity branch. The beach is covered with tin cans of varying weights arranged in a single line, indexed from 0 to n-1.
Stacey uses a scooper that can pick up three adjacent cans at a time. For each selection:
1. She identifies the lightest remaining can, with weight w
2. She uses the scooper to pick up that
Asked in: JPMORGAN
Perform a series of operations on a given array of integers. Each operation consists of two indices that define a subarray to reverse, inclusive of those indices.
Return the resulting array after all operations have been applied in the specified order.
Example
arr = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
operations = [[0, 9], [4, 5], [3, 6], [2, 7], [1, 8], [0, 9]]
In the first operation,
Asked in: JPMORGAN
Data scientists at Amazon are working on a utility for detecting similar passwords in their security systems. The utility finds anagram patterns in pairs of passwords. A pair of passwords is considered similar if they are anagrams after removing any number of occurrences of at most one character from each password.
Given n pairs of passwords, for each pair, attempt to make them anagrams. Return
Asked in: AMAZON