Homework Week 4 Array Based Sequence
Homework Week 4 Array Based Sequence
For example, a leader board with capacity 10 is called a top 10 leader board which will
contain 10 highest scores. Initially, it accepts first 10 ten scores in descending order, i.e
scores from highest to lowest. When a later entry is considered:
• if it is lower than all of scores in top 10, then there will be no change in the lead
board.
• if the entry is higher than one of top 10, it will be placed in appropriate rank and
the last element of the leader board, corresponding to the current lowest score, will
be removed.
1 class LeaderBoard :
2 """ Fixed length sequence of high scores in descending order """
3
4 def __init__ ( self , capacity ) :
5 """ Initialize leader board with given maximum capacity
6 All entries are initially None
7 Capacity must be a positive integer """
8 pass
9
10 def __len__ ( self ) :
11 """ Return the number of non None elements in the board """
12 pass
13
14 def get_player ( self , player ) :
15 """ Find a player in leader board using his name
Data Structures and Algorithms Homework Week 4
Create a leader board for top 7 players in DSA Game. First 7 players are:
1 [( ' Catto ' , 25) , ( ' Doggo ' , 28) , ( ' Bunny ' , 19) , ( ' Panda ' , 20) , ( ' Snaky ' ,
30) , ( ' Racoon ' , 23) , ( ' Larma ' , 21) ]
Initialize an dynamic array object and use the implemented fibonacci method to calculate
the 50th, 70th and 100th number of Fibonacci sequence.
2
Data Structures and Algorithms Homework Week 4
You want to maximize your profit by choosing a single day to buy one stock and choos-
ing a different day in the future to sell that stock. Note that in the array you only
choose one day to buy and one day to sell.
Implement a function to return the maximum profit you can achieve from this transaction,
If you cannot achieve any profit, return 0. See the examples below:
1 price = [7 , 1 , 5 , 3 , 6 , 4]
2 best_profit ( price )
3 >>> 5
4 """ Explanation : Buy on day 2 ( price = 1) and sell on day 5 ( price = 6)
then profit = 6 - 1 = 5. Note that buying on day 2 and selling on
day 1 is not allowed because you must buy before you sell . """
5
6 price = [7 , 6 , 4 , 3 , 1]
7 best_profit ( price )
8 >>> 0
9 """ Explanation : In the future prices keep decrease so your max profit
is 0 """
Perform Caesar decryption for the following strings with shift parameter = 7:
1 [ ' Jhlzhy Jpwoly h zptwsl tlaovk ' , ' Jvunyhabshapvu , fvb mpuhssf mpupzolk
aopz ovtldvyr ']