TechInfo

Super Movement CodeKaze June23 Round 2 Solution || India’s Biggest Hiring Challenge

Super Movement CodeKaze June23 Round 2 Solution || India’s Biggest Hiring Challenge

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW
JoinScishowEngineerTelegram

Super Movement CodeKaze June23 Round 2 Solution || India’s Biggest Hiring Challenge

Problem Statement

There are ‘N’ platforms and an array ‘A’ of length ‘N’. You are standing at platform ‘0’.

You can instantly jump forward or backward ‘K’ platforms with your superpower. Or you can walk to the next platform in a few seconds like a normal human being.

It takes ‘| A[ i ] – A[ i + 1 ] |’ seconds to walk from platform ‘i’ to platform ‘i + 1’. You CANNOT go from platform ‘i + 1’ to platform ‘i’.

Find the minimum time you need to visit all ‘N’ platforms at least once.

For Example :
Let 'N' = 4, 'K' = 2, 'A' = [ 1, 5, 4, 7 ].
You can take the route '0' → '2' → '3' → '1' to visit all 'N' platforms once.
Walking from platform '2' to platform '3' takes '| 4 - 7 | = 3' seconds.
Both other movements are done instantly with your superpower.
It can be shown that this is the minimum possible time.
Thus, the answer is '3'.
Detailed explanation ( Input/output format, Notes, Images )
Constraints :
1 <= 'T' <= 10
3 <= 'N' <= 10^5
2 <= 'K' < 'N'
1 <= 'A[i]' <= 10^9

Time Limit: 1 sec
Sample Input 1 :
2
5 3
7 6 14 2 1
6 3
1 1 1 1 1 1
Sample Output 1 :
9
0
Explanation Of Sample Input 1 :
First test case:-
You can take the route '0' → '3' → '4' → '1' → '2' to visit all 'N' platforms once.
Walking from platform '3' to platform '4' takes '| 2 - 1 | = 1' second.
Walking from platform '1' to platform '2' takes '| 6 - 14 | = 8' seconds.
Both other movements are done instantly with your superpower.
It can be shown that this is the minimum possible time.
Thus, the answer is '9'.

Second test case:-
Since all the platforms have the same 'A[i]', walking time is 0 seconds, meaning walking is instant.
You can take the straight route '0' → '1' → '2' → '3' → '4' → '5' to visit all 'N' platforms once in 0 seconds.
Thus, the answer is '0'.
Sample Input 2 :
2
10 4
1 7 3 11 9 20 13 6 25 100
11 2
7 2 3 4 5 6 7 8 9 10 10
Sample Output 2 :
17
1
Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW
JoinScishowEngineerTelegram


6 digit code appear after 69 seconds.
 

Wait for  Solution


We are Still Solving…. Please Visit Our Social Media Handle Till Then

Here Discuss About Super Movement CodeKaze June23 Round 2 Solution || India’s Biggest Hiring Challenge

Super Movement CodeKaze June23 Round 2 Solution || India’s Biggest Hiring Challenge

 

Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here ScishowEngineer   Then Follow US HERE and Join Telegram.

If You Want To Learn Something New Then Visit Our Official Channel YOUTUBE