Posts

Showing posts from April, 2021

Python: Finding largest continuous sum in a list/array

 Problem Statement: Given a list of integers (both positive and negative) find the largest continuous sum. e.g.  Input: list1 = [1, 2, -1, 3, 4, 10, 10, -10, -1] Output: 29 Solution: def   largest_cont_sum ( list1 ):     max_sum  =  current_sum  =   0           if   len ( list1 )   ==   0 :          return   " There is no any element in the List "           for  num  in  list1 :         current_sum  =   max ( current_sum  +  num ,  num )         max_sum  =   max ( current_sum ,  max_sum )           return  max_sum list1  =   [ 1 , 2 ,- 1 , 3 , 4 , 10 , 10 ,- 10 ,- 1 ] print ...

Python: Find the missing element

 Problem Statement: Consider array/list of non-negative integers. The second array/list is formed by shuffling the elements of the first array/list and deleting a random element. Given these two arrays/lists, find which element is missing in second array. e.g. list1 = [1, 2, 3, 4, 5, 6] list2 = [2, 5, 4, 6, 3] here missing element is 1. Solution: def   missing_ele ( list1 ,   list2 ):     list1 . sort ()     list2 . sort ()      for  num1 ,  num2  in   zip ( list1 ,  list2 ):          if  num1  !=  num2 :              return  num1      return  list1 [- 1 ] list1  =   [ 1 ,   2 ,   3 ,   4 ,   5 ,   6 ] list2  =   [ 2 ,   4 ,   6 ,   3 ,   5 ] print ( " Missing element is:...

555 Timer as Monostable Multivibrator

Here, I have simulated a Monostable Multivibrator in Proteus design suite.