Category: Uncategorized
Protected: Left Rotation in array using Python. (HackerRank Problem)
Protected: Problem on updating the Values of a dictionary, keeping the key constant. (Flipkart Interview Question – 2019)
Convert integer to binary using Stack in Python
def int_to_binary(n):
arr = []
string = ""
while n>0:
a = n%2
arr.append(a)
n = n//2
string = string + str(a)
return string[-1::-1]
print(int_to_binary(242))
Protected: Dynamic Programming (Part 1) with Proper Comments – Interview Questions (Easily Understandable)
Protected: Show the common characters between 2 strings and print the output in the form of an array in Python (Godrej Interview Question)
Protected: Find the Second Largest Number from an unsorted list of array in Python using least time complexity (Ixia Interview Question)
Counting total number of consonants in a string in iterative way using Python (Google Interview Question)
string = 'Sayan'
viowels = 'aeiou'
count=0
for items in range(len(string)):
if string[items].lower() not in viowels and string[items].isalpha:
count+=1
print(count)
Counting total number of consonants in a string in recursive way using Python (Google Interview Question)
viowels = 'aeiou'
def recursive_consonants(string):
if string == '':
return 0
if string[0].lower() not in viowels and string[0].isalpha():
return 1+recursive_consonants(string[1:])
else:
return recursive_consonants(string[1:])
print(recursive_consonants('Sayan'))
Working with readline(), readlines() functions, closed keyword in Python
- readline() returns only one line of the file if not provided with any argument.
- readline() takes only one integer argument and it will print the that number of characters that are passed in the arguments.
- readlines() returns all the lines of the file in the form of a list.
- ‘close’ checks whether a file is closed or not.
- ‘close’ returns a boolean value either True if the file is closed or False if the file is not closed.
f = open('file1.txt', 'r')
print(f.readline(), end = "")
lines = f.readlines()
for line in lines:
print(line, end = "")
print(" ")
print(f.closed)
f.close()
print(f.closed)
OUTPUT :
Hey, I'm Sayan Dey.
I'm from Chandannagar.
My emai id is - d.sayan1998@gamil.com.
There's a big pandemic situation in the world. Hope everyone is okay.
Stay at home.
Stay safe.
Use sanitizers.
Use hand gloves.
Use handwashes.
False
True
CONTENT OF MY FILE :
Hey, I’m Sayan Dey.
I’m from Chandannagar.
My emai id is – d.sayan1998@gamil.com.
There’s a big pandemic situation in the world. Hope everyone is okay.
Stay at home.
Stay safe.
Use sanitizers.
Use hand gloves.
Use handwashes.