Skip to content

Commit

Permalink
Day-38
Browse files Browse the repository at this point in the history
  • Loading branch information
Maahi10001 authored Mar 29, 2022
1 parent 5934704 commit a6884c2
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Day-38/Day-38-p1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'''
Given a array of "array of words" and "characters",
find the sum of length of all nice words using those characters.
nice word: a word is nice, if it can be formed by characters.
example:
input =cat bt hat tree
atach
output=6
The words that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.
input =apple orange bat tree
atbeppol
output =8
'''
#solution
def getthelength(arr,s):
a=[]
for i in arr:
count=0
for j in range(len(i)):
if i[j] in s:
count+=1
if(count==len(i)):
a.append(count)
return sum(a)
if __name__=="__main__":
arr=list(map(str,input().split()))
s=input()
print(getthelength(arr,s))
48 changes: 48 additions & 0 deletions Day-38/Day-38-p2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'''
Given a word w, return the number of substrings with out duplicate characters of length 3 in w.
ex:
input =xyzzaz
output =1
there are 4 substrings of size 3
xyz, yzz,zza,zaz
out of this only xyz has no duplicate characters so print 1.
ex:
input =aababcabc
ouput =4
there are 7 substrings of size 3
aab,aba,bab,abc,bca,cab,abc
from the above abc,bca,cab,abc are having unique characters.
'''
#solution
def countthestrings(s):
x,y,count=0,1,0
while(x<=len(s) and y<=len(s)):
if(len(s[x:y])==3):
if(len(set(s[x:y]))==3):
print(s[x:y])
count+=1
x+=1
y+=1
else:
y+=1

'''count=0
for i in range(len(s)):
for j in range(i+1,len(s)+1):
#print(s[i:j])
if(len(s[i:j])==3): #brute force
#print(s[i:j])
if(len(set(s[i:j]))==3):
count+=1'''
return count
#return False

if __name__=="__main__":
s=input()
print(countthestrings(s))
86 changes: 86 additions & 0 deletions Day-38/Day-38-p3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'''
Siddarth is working with a list of integers, 0-indexed list.
The list is said to be decent list, if the sum of the inteers at odd indices
equal to the sum of integers at even indices in the list.
Now, siddarth can choose any index position, and delete the element from the list.
and check whether the resultant list is a decent list or not.
Due to the deletion of an element, the index postions may vary.
For example, if the list is [2,1,3,4,1] :
- delete the element at index 1 => list is [2,3,4,1]
- delete the element at index 2 => list is [2,1,4,1]
- delete the element at index 3 => list is [2,1,3,1]
- delete the element at index 4 => list is [2,1,3,4]
Siddarth has to find out how many indices you can remove one at a time and,
check that the resultant list becomes a decent list.
Your task is to help siddarth to find the count of all such indices.
Input Format:
-------------
Line-1: An integer N, number of elements in the list.
Line-2: N space separated integers, the list.
Output Format:
--------------
Print an integer, number of indices you can find.
Sample Input-1:
---------------
5
1 2 2 1 2
Sample Output-1:
----------------
1
Sample Input-2:
---------------
5
2 2 2 2 2
Sample Output-2:
----------------
5
Sample Input-3:
---------------
4
3 2 7 5
Sample Output-3:
----------------
1
'''
#solution
def getthepossible(n,l):
x,count=0,0
while(x<n):
oddsum,evensum=0,0
temp=list(l)
temp.pop(x)
#print(temp)
for i in range(len(temp)):
if i%2==0:
evensum+=temp[i]
#print(evensum)
else:
oddsum+=temp[i]
#print(oddsum)
temp.clear()
x+=1

if(evensum==oddsum):
count+=1
return count
if __name__=="__main__":
n=int(input())
l=list(map(int,input().split()))
print(getthepossible(n,l))

0 comments on commit a6884c2

Please sign in to comment.