Posts

Showing posts with the label coding interview questions

Number patterns in python

As we all know,python is an easy  to start programming language. Patterns are the most problems given in hiring interviews. So,lets get started fully on number patterns. problem 1 : print the following pattern. sample input 1:            5 sample output 1: 1 2 4 4 8 8 8 16 16 16 16 32 32 32 32 sample input 2: 3 sample output 2: 1 2 4 4 8 8 python code: n=int(input()) k=1 for i in range(0,n):     for j in range(0,i+1):         if j>=1:             print(k,end=' ')         elif j<2:             print(k,end=' ')             k=k*2     print('\n')  problem 2: sample input :4 sample output: 1 3 2 6 5 4 10 9 8 7 python code: n=int(input()) k=1 for i in range(n):     l=[]     h=''     for j in range(i+1): ...

fibonacci series using function

As we all know,python is an easy  to start programming language. coding program are the most problems given in hiring interviews. So,lets get started with basic programs. problem :find the nth element in fibonacci series. sample input:7 sample output:13 python code: def fib(n):     if(n==0):         return 0     elif(n==1):         return 1     else:         return fib(n-1)+fib(n-2) n=int(input('enter an integer value')) for i in range(0,n+1):     x=fib(i) print(x)