100DayChallenge

10 flashcards · Programming Languages · by k30rahul

  1. Swap two numbers without a temporary variable. Eg: a=5,b=10 After swapping a=10,b=5

    a,b=b,a

  2. Accessing elements in a list with their index. Given arr=[ 'Hello' , 'World' , 'Namaste' ] Print Hello Namaste

  3. Given arr=[1,2,3,4,5]. Reverse the list.

    arr=arr[::-1]

  4. Convert all the given string to lowercase word="LOWER" Output lower

  5. List Comprehension Create a list with first 10 natural numbers.

    even=[no for no in range(1,11) ]

  6. Join the elements in a list without using a loop. Eg: a= ['Welcome' , 'to' , 'this', 'tutorial'] Output: Welcome to this tutorial

  7. Using only a bit wise operator find whether a number is odd or not

    def find_if_odd(n): return n&1

  8. Using bit and bit wise operators check whether any possible permutation of the given word produces a palindrome.

  9. Algorithm to find the largest value in a BST?

    1.Traverse the node from root to right until NULL 2.If NULL return the value of current root node

  10. Given a binary tree, invert the given tree such that left leaves are now the right leaves and vice versa.

    def invert(tree): if not tree: return tree.left,tree.right=tree.right,tree.left invert(tree.left) invert(tree.right) return tree