mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 14:56:27 -04:00
some ex
This commit is contained in:
parent
9b4c8df7f7
commit
47e5ee3918
2 changed files with 92 additions and 0 deletions
41
real_interview_problems/2n_packets.py
Normal file
41
real_interview_problems/2n_packets.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
#!/bin/python
|
||||
|
||||
import math
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import sys
|
||||
|
||||
# Complete the 'largestRepackaged' function below.
|
||||
#
|
||||
# The function is expected to return a LONG_INTEGER.
|
||||
# The function accepts INTEGER_ARRAY arrivingPackets as parameter.
|
||||
#
|
||||
|
||||
def largestRepackaged(arrivingPackets):
|
||||
|
||||
packet_size = arrivingPackets[0]
|
||||
packets = arrivingPackets[1:]
|
||||
largest_packet = 0
|
||||
remaining = 0
|
||||
|
||||
for packet in packets:
|
||||
print packet
|
||||
if remaining:
|
||||
packet += remaining
|
||||
remaining = 0
|
||||
|
||||
if packet % 2 != 0:
|
||||
remaining = packet % 2
|
||||
packet -= remaining
|
||||
|
||||
if packet > largest_packet:
|
||||
largest_packet = packet
|
||||
|
||||
return largest_packet
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
arrivingPackets= [5, 1, 2, 4, 7, 5]
|
||||
|
||||
print(largestRepackaged(arrivingPackets))
|
Loading…
Add table
Add a link
Reference in a new issue