-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprac_3.py
More file actions
45 lines (35 loc) · 1.09 KB
/
Copy pathprac_3.py
File metadata and controls
45 lines (35 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Name : PRATHAM MODI
# ID : 20CE056
# Aim : Find Captain Room Number
# GITHUB LINK : https://github.com/prathammodi333/python-programs
n = int(input("enter the number of members per group : "))
myLiST = [int(item) for item in input("Enter the list items : ").split()]
# using list comprehension
listToStr = ''.join([str(elem) for elem in myLiST])
new_str = listToStr
NO_OF_CHARS = 256
# Returns an array of size 256 containing count
# of characters in the passed char array
def getCharCountArray(string):
count = [0] * NO_OF_CHARS
for i in string:
count[ord(i)]+= 1
return count
# The function returns index of first non-repeating
# character in a string. If all characters are repeating
# then returns -1
def firstNonRepeating(string):
count = getCharCountArray(string)
index = -1
k = 0
for i in string:
if count[ord(i)] == 1:
index = k
break
k += 1
return index
index = firstNonRepeating(new_str)
if index == 1:
print ("Either all characters are repeating or string is empty")
else:
print ("captain's room is : " , new_str[index])