Posts

Showing posts from March, 2021

Seven different ways of duplicity checks in an Array

 Problem Statement: Given an Array of positive Integers Check for the Duplicity with optimum Time Complexity & Space Complexity.  Solution: There are many ways to solve the stated problem. The First criteria to solution is  determined by  fulfilment of customised requirements on expected output for duplicity problem i.e "Correctness of the solution" Examples of requirements :   1. Check for Duplicity only (Elements are not required) 2. Get the list of duplicate integers  3. Remove the duplicate integers  4. Find the maximum repeated integer. 5. Find the 1st repeated Integer. 6. Find the smallest repeated Integer.   The second  criteria to the solution is determined by Time Complexity and Space Complexity. The most efficient solution in to this problem would be : Time Complexity O(n)/O(1)  at worst case and Space Complexity O(1).   In the subsequent contents of this article , we will the seven different ways of checking...

Python-3 : dictionary problems & Solutions

  python-3 : dictionary problems & Solutions Problem 1. Design a Switch Case using Dictionary in python for following problem: Take OS names as inputs : RHEL, CENTOS, UBUNTU, FEDORA, AmazonLinux, KALILinux and return the Kernel Version. (Note: 1. Use Dummy Kernel versions as 3.0, 3.1, 3.2,3.3,3.4 & 3.5  for the OS names respectively. 2. The User Input name should be handled as case insensitiveness. 3. Default Kernel Version is 3.4.) Solutions : def switch (os):     return {         'rhel' : '3.0' ,         'ubuntu' : '3.2' ,         'centos' : '3.1' ,         'fedora' : '3.3' ,         'amazonlinux' : '3.4' ,         'kalilinux' : '3.5'     }.get(os.lower() , '4.0' ) print (switch( 'RHEL' )) Problem 2. Give a List of Dict :  [{'...