mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 06:46:18 -04:00
reorganize dir
Signed-off-by: Mia Steinkirch <mia.steinkirch@gmail.com>
This commit is contained in:
parent
1b6f705e7c
commit
a8e71c50db
276 changed files with 23954 additions and 0 deletions
41
ebook_src/real_interview_problems/2n_packets.py
Normal file
41
ebook_src/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