100DayChallenge
10 flashcards · Programming Languages · by k30rahul
Swap two numbers without a temporary variable. Eg: a=5,b=10 After swapping a=10,b=5
a,b=b,a
Accessing elements in a list with their index. Given arr=[ 'Hello' , 'World' , 'Namaste' ] Print Hello Namaste
Given arr=[1,2,3,4,5]. Reverse the list.
arr=arr[::-1]
Convert all the given string to lowercase word="LOWER" Output lower
List Comprehension Create a list with first 10 natural numbers.
even=[no for no in range(1,11) ]
Join the elements in a list without using a loop. Eg: a= ['Welcome' , 'to' , 'this', 'tutorial'] Output: Welcome to this tutorial
Using only a bit wise operator find whether a number is odd or not
def find_if_odd(n): return n&1
Using bit and bit wise operators check whether any possible permutation of the given word produces a palindrome.
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
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