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
|
358 Discussions
|
Please Login in order to post a comment
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:
Just have modify mergesort and count the inversion(shift) .
def insertionSort(arr):#by using mergesort count = 0 if len(arr) > 1: mid = len(arr)//2 left_list = arr[:mid] right_list = arr[mid:] count = count + insertionSort(left_list) count = count + insertionSort(right_list) count = count + merge(left_list,right_list,arr) return count def merge(left_list,right_list,arr): i=0 j=0 k=0 count = 0 mid = len(arr)//2 while i
what the hell , if you are getting wrong answer and if you think your code is correct , then the convert the integer to long in pre written code , they said that the range is in integer's range but it isn't.