Skip to content

Commit f6abe0e

Browse files
committed
Accolite,Tesco
1 parent 8c888e9 commit f6abe0e

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

isSubsequence.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''
2+
Given two strings str1 and str2, find if str1 is a subsequence of str2. A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements (source: wiki). Expected time complexity is linear.
3+
'''
4+
#REcursive solution
5+
def isSubsequence(s1, s2, m, n):
6+
if m == 0:
7+
return True
8+
if n == 0:
9+
return False
10+
if s1[m-1] == s2[n-1]:
11+
return isSubsequence(s1, s2, m-1, n-1)
12+
return isSubsequence(s1,s2,m,n-1)
13+
14+
s1 = "rahul"
15+
s2 = "driashwaulri"
16+
m = len(s1)
17+
n = len(s2)
18+
if isSubsequence(s1, s2, m, n):
19+
print "True"
20+
else:
21+
print "False"

printPattern.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'''Print pattern like this
2+
3+
Example:
4+
Input: 1
5+
Output: 0
6+
7+
Input: 2
8+
Output:
9+
0 0
10+
0 1
11+
1 0
12+
1 1
13+
14+
Input: 3
15+
Output:
16+
0 0 0
17+
0 0 1
18+
0 1 0
19+
0 1 1
20+
1 0 0
21+
1 0 1
22+
1 1 0
23+
1 1 1
24+
'''
25+
def printbinary(n):
26+
lis = []
27+
for i in range(2**n):
28+
lis.append(bin(i)[2:])
29+
return lis
30+
n = int(raw_input())
31+
lis = printbinary(n)
32+
for i in lis:
33+
print i.rjust(n, '0')

0 commit comments

Comments
 (0)