Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

You should complete the function and ensure it produces the correct output against all test cases possible within the constraints highlighted. The runtime of the

You should complete the function and ensure it produces the correct output against all test cases possible within the constraints highlighted. The runtime of the program is important so it is best to use an algorithm in the code which will not timeout.

image text in transcribedimage text in transcribed

Bullet Statistics HHackerRank A forensic scientist is studying the movement of a weirdly shaped bullet moving through some material of irregular density. Using her sophisticated equipment, she can obtain the speed in millimeters per millisecond (mm/ms) with which the bullet is moving for the entire length of its distance traveled. The recorded speed is always a positive integer Note that if at time tms, the bullet was at distance z mm, and her instrument recorded a speed of v mm/ms, then this means that at time t + 1 ms, the bullet was at a distance u mm. Along the trajectory of the bullet, she has a number of specially marked points, which are at known distances along the path. She wants to know the earliest time, to the nearest millisecond, when the bullet would have reached each landmark. If the bullet never reaches a landmark, she reports the time as-1, otherwise, she reports the smallest number of milliseconds after which the bullet would have either arrived at, or just passed, the landmark. Input Format Line 1: the total time (in milliseconds) for which data was collected. Line 2: U1 . . . ty the instantaneous velocities measured for each millisecond of the experiment. Line 3: n the total number of landmark points to be queried Line 4: p1..Pn the distances in mm of the landmark points being queried (not in any particular order) Constraints 1st s108 1n 105 1 v103 (1it 0 Sp 10 (for1 findTimes (List speeds, List queries) 25 26 27 28 Write your code here 30 31 ypublic class Solution t 32 public static void main(String[] args) throws IOException BufferedReader bufferedReadernew BufferedReader (new InputStreamReader (System.in)); 35 36 37 38 39 40 Bufferedwriter bufferedwriternew BufferedwWriter(new FileWriter (System.getenv("OUTPUT_PATH"))) int n Integer.parseInt (bufferedReader.readLine ().trim)); List Integer> speeds Stream.of (bufferedReader.readLine().replaceALl("Is+$", "").split(" ")) .map (Integer::parseInt) collect (tolist()); int q Integer.parseInt (bufferedReader.readLine).trim)); 43 List queries Stream.of (bufferedReader.readLine().replaceALl("s+$", "").split(" ")) 45 map (Integer: :parseInt) .collect (toList)); 47 48 49 List results Result.findTimes (speeds, queries); bufferedWriter.write( results.stream 52 53 54 .map (Object::toString) .collect (joining(" ")) 56 57 58 59 60 bufferedReader.close(); bufferedWriter.close()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions