We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Insertion Sort Advanced Analysis
Insertion Sort Advanced Analysis
Sort by
recency
|
360 Discussions
|
Please Login in order to post a comment
Use long Instead of int
If you are using the mergesort's count inversion method then kindly use long for you answer (counter variable basically) instead of int. I was stuck since last 2 hours and then I got to know that long is acceptable instead of int in answer. So try your solution with long If you think your count inversion solution is correct.
Idk why insertion sort that test on very large array or my skill issue. i was trying binany search on my insertion sort to improve speed, still timeout 4 tests. Im not sure i can use orther sort like merge sort or quick sort. so this is my code.
Implement a prototype of a UDP network protocol.
There is a 2d array of size n x 2, requests. At time t = requests[i][0], requests[i][1] packets are to be sent over the network. The network can hold at most max_packets packets in the pipeline. It delivers the data to the client at rate packets per second, i.e. rate packets are removed from the queue and delivered to the client every second.
If the number of packets exceeds max_packets at any time, the packets remaining at that time are dropped.
Given the array requests, and the integers, max_packets, and rate, find the total number of packets that are dropped.
Example
Suppose requests = [[1, 8], [4, 9], [6, 7]], rate = 2, and max_packets= 10.
Curious why this solution in Python gets a runtime error for about half of the test cases - I am guessing it's something to do with there being an earlier potential exit point for the loop than simply (s < lenA) or that I shouldn't be using functions like index or min in the solution and instead stick to primitive operations. I'm pretty much a novice, so any advice would help:
Ruby solution: