This round involved two algorithmic questions designed to assess problem-solving skills, understanding of data structures, and the ability to optimize for time and space complexity.
You're on a hiking expedition across a series of hills, represented by an array elevations, where each element indicates the height of a hill. Starting from hill 0, your objective is to travel as far as possible using a limited number of grappling hooks and a stockpile of climbing gear units.
To move from hill i to hill i + 1:
If the next hill is at the same height or lower, you can walk without using any equipment.
If the next hill is higher, you must either:
(elevations[i+1] - elevations[i]).You may choose when to use grappling hooks or climbing gear. The objective is to plan your resource usage wisely to reach the farthest hill possible.
int furthestHillIndex(vector<int>& elevations, int climbing_gears, int grappling_hook);Input: elevations = [4,2,7,6,9,14,12], climbing_gears = 5, grappling_hook = 1
Output: 4
Input: elevations = [14,3,19,3], climbing_gears = 17, grappling_hook = 0
Output: 3
Input: elevations = [3,11,7,11,15], climbing_gears = 8, grappling_hook = 1
Output: 4
You are given a string S consisting only of the characters 'A', 'B', 'C', and 'D'. The length of the string is always a multiple of 4 (i.e., length = 4 * N for some positive integer N).
A string is considered balanced if every character 'A', 'B', 'C', and 'D' appears exactly N times.
Your task is to find the minimum length of a contiguous substring that can be replaced with any arbitrary sequence (of the same length) such that the entire string becomes balanced.
int minSubstringToBalance(string s);Identify the shortest substring to replace, so that the final string has an equal number of each character, i.e., count('A') = count('B') = count('C') = count('D') = N.
Input: "AAAABBCD"
Output: 2
(Replace "AA" with "CD")
Input: "ABBBADAA"
Output: 3
Input: "BACD"
Output: 0
(Already balanced)
even after solving both the questions in time and with excepted time and space complexities , I was not shortlisted further and no proper feedback is provided as well.