12/23/2023 0 Comments Quip salesforce hackerrank![]() ![]() Q3: Explain what is Reactor Pattern in Node.js? Find the minimum number of fountains that must be switched on to cover the road.įor position 1: locations = 0, max((1 – 0),ġ) to mini (1+0), 3) gives range = 1 to 1įor position 2: locations = 2, max((2-2),ġ) to min( (2+2), 3) gives range = 1 to 3įor position 3: locations = 1, max( (3-1),ġ) to min( (3+1), 3) gives range = 2 to 3įor the entire length of this road to be covered, only the light at position 2 needs to be activated.Enter fullscreen mode Exit fullscreen mode Initially all the lights are switched off. The ith light has a coverage limit of locations that can range from the position max((i – locations), 1) to min((i + locations), n ) (Closed intervals). Locations (an array) represents the coverage limit of these lights. Problem Statement -: Street Lights are installed at every position along a 1-D road of length n. Public static int collectMax(int n,int m,int grid) Public static void initializeDp(int dp,int item) ![]() Return dp = Math.max(ch1, Math.max(ch2, Math.max(ch3, ch4))) Int ch3 = -1 * Integer.MAX_VALUE, ch4 = -1 * Integer.MAX_VALUE Int ch1 = -1 * Integer.MAX_VALUE, ch2 = -1 * Integer.MAX_VALUE Public static int solve(int n, int m, int grid,int dp, int row1,int col1, int row2) Public static int cost(int grid, int row1, int col1,int row2, int col2) Int ans = cur + max(op1, max(op2, max(op3, op4))) Int : maximum number of passengers that can be collected. Move down one to the destination.Cell (1,0) is blocked,So the return path is the reverse of the path to the airport.All Paths have been explored and one passenger is collected. Start at top left corner.Move right one collecting a passenger. The goal is to collect as many passengers as possible so that the driver can maximize his earnings.If there is no valid path between (0,0) and (n-1,n-1),then no passenger can be picked. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |