"Least number of lights to switch ON" Udaan | Data Science FTE

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2022-08-05Added By Anonymous
Source: Link
Company: Udaan
Role: Data Science FTE
Interview Stage: unknown
Location: unknown
Year: unknown

Original Experience:
INPUTS: Given a train with 'N' compartments of different lengths, a tunnel of length 'L', an array of length of each of the N compartments, and a boolean array of whether the light is switched "ON" (1) or OFF (0) in each of the N compartments. Constraints: 1) Atleast 1 compartment inside the tunnel should be lit. If not you'll have to turn on the lights in any of the compartments inside the tunnel. 2) Minimize electricity usage,i.e number of lights you are turning ON (the input is fixed) Output: the number of lights you need to turn ON to satisfy the constraints given the following inputs. Eg: N=7 L=10 len[] = 5 3 4 5 9 9 9 num[] = 1 0 0 0 1 0 0 Output: 2 Explanation: You'll need to switch ON the light in compartment 4 and compartment 7,so 2 is the output.
Comments