forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringkth.py
More file actions
31 lines (29 loc) · 775 Bytes
/
stringkth.py
File metadata and controls
31 lines (29 loc) · 775 Bytes
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
'''
A program to remove the kth index from a string and print the remaining string.In case the value of k
is greater than length of string then return the complete string as it is.
'''
#main function
def main():
s=input("enter a string")
k=int(input("enter the index"))
l=len(s)
#Check whether the value of k is greater than length
if(k>l):
print(s)
#If k is less than length of string then remove the kth index value
else:
s1=''
for i in range(0,l):
if(i!=k):
s1=s1+s[i]
print(s1)
if __name__== "__main__":
main()
'''
Time Complexity:O(n),n is length of string
Space Complexity:O(1)
Input/Output:
enter a string python
enter the index 2
pyhon
'''