I am a software application developer currently employed at DXC Technology in Hyderabad. I have a strong passion for learning and exploring new things, and I am highly enthusiastic about my work. I en...
Basaveshwar Engineering College 2019
Python - Default language
My Stats
EXP gained
3122
Level
5 (Champion)
Community stats
Discussions
0
2
Know more
168
Total problems solved
140
Easy
26
Moderate
2
Hard
0
Ninja

Current streak:

0 days

Longest streak:

2 days

Less

More

Achievements
4
Ronin
Topics
Math
Backtracking
+ 2 more
8
Samurai
Topics
Sorting
Arrays
+ 5 more
1
Sensei
Topics
Recursion
Discussions
Python_Soln
Interview problems
``````from sys import stdin, setrecursionlimit
import queue

setrecursionlimit(10 ** 6)

#Following is the structure used to represent the Binary Tree Node
class BinaryTreeNode:
def __init__(self, data):
self.data = data
self.left = None
self.right = None

def buildTree(preOrder, inOrder):
if len(preOrder) == 0:
return None
rootData = preOrder[0]
root = BinaryTreeNode(rootData)
rootIndex = -1
for i in range(0, len(inOrder)):
if inOrder[i] == rootData:
rootIndex = i
break
if rootIndex == -1:
return None
leftInorder = inOrder[0:rootIndex]
rightInorder = inOrder[rootIndex+1:]
lenLeft = len(leftInorder)
leftPreorder = preOrder[1:lenLeft+1]
rightPreorder = preOrder[lenLeft+1:]
leftChild = buildTree(leftPreorder, leftInorder)
rightChild = buildTree(rightPreorder, rightInorder)
root.left = leftChild
root.right = rightChild
return root

'''-------------------------- Utility Functions --------------------------'''

def printLevelWise(root):
if root is None:
return

pendingNodes = queue.Queue()
pendingNodes.put(root)
pendingNodes.put(None)

while not pendingNodes.empty():
frontNode = pendingNodes.get()

if frontNode is None:
print()

if not pendingNodes.empty():
pendingNodes.put(None)

else:
print(frontNode.data, end=" ")

if frontNode.left is not None:
pendingNodes.put(frontNode.left)

if frontNode.right is not None:
pendingNodes.put(frontNode.right)

#Taking level-order input using fast I/O method
def takeInput():

if n == 0:
return [], [], 0

return preOrder, inOrder, n

# Main
preOrder, inOrder, n = takeInput()
root = buildTree(preOrder, inOrder)
printLevelWise(root)
``````
Prashant Marabe
Published On 19-Jan-2023
48 views
0 replies
Python_Soln
Interview problems
``````from sys import stdin, setrecursionlimit
import queue

setrecursionlimit(10 ** 6)

# Following the structure used for Binary Tree
class BinaryTreeNode:
def __init__(self, data):
self.data = data
self.left = None
self.right = None

def preOrder(root):
if root is None:
return
preOrder(root.left)
preOrder(root.right)
print(root.data, end=' ')

#Taking level-order input using fast I/O method
def takeInput():
start = 0

length = len(levelOrder)

root = BinaryTreeNode(levelOrder[start])
start += 1

q = queue.Queue()
q.put(root)

while not q.empty():
currentNode = q.get()

leftChild = levelOrder[start]
start += 1

if leftChild != -1:
leftNode = BinaryTreeNode(leftChild)
currentNode.left = leftNode
q.put(leftNode)

rightChild = levelOrder[start]
start += 1

if rightChild != -1:
rightNode = BinaryTreeNode(rightChild)
currentNode.right = rightNode
q.put(rightNode)

return root

# Main
root = takeInput()
preOrder(root)
``````
Prashant Marabe
Published On 16-Jan-2023
64 views
0 replies
Python_Soln
Interview problems
``````from sys import stdin, setrecursionlimit
import queue

setrecursionlimit(10 ** 6)

# Following the structure used for Binary Tree
class BinaryTreeNode:
def __init__(self, data):
self.data = data
self.left = None
self.right = None

def preOrder(root):
if root != None:
print(root.data,end=" ")
preOrder(root.left)
preOrder(root.right)

# def insert(root,newValue):

#     if root is None:
#         root=BinaryTreeNode(newValue)
#         return root

#     if newValue<root.data:
#         root.leftChild=insert(root.leftChild,newValue)
#     else:

#         root.rightChild=insert(root.rightChild,newValue)
#     return root
# def preOrder(root):

#         if root==None:
#             return

#         print(root.data)

#         preOrder(root.leftChild)

#         preOrder(root.rightChild)
# root= insert(None,1)
# insert(root,2)
# insert(root,3)
# insert(root,4)
# insert(root,5)
# insert(root,6)
# insert(root,7)
# insert(root,-1)
# insert(root,-1)
# insert(root,-1)
# insert(root,-1)
# insert(root,-1)
# insert(root,-1)
# insert(root,-1)
# print("Printing values of binary tree in preorder Traversal.")
# preorder(root)

#Taking level-order input using fast I/O method
def takeInput():
start = 0

length = len(levelOrder)

root = BinaryTreeNode(levelOrder[start])
start += 1

q = queue.Queue()
q.put(root)

while not q.empty():
currentNode = q.get()

leftChild = levelOrder[start]
start += 1

if leftChild != -1:
leftNode = BinaryTreeNode(leftChild)
currentNode.left =leftNode
q.put(leftNode)

rightChild = levelOrder[start]
start += 1

if rightChild != -1:
rightNode = BinaryTreeNode(rightChild)
currentNode.right =rightNode
q.put(rightNode)

return root

# Main
root = takeInput()
preOrder(root)

``````
Prashant Marabe
Published On 16-Jan-2023
96 views
0 replies
Python_Soln
Interview problems
``````
from sys import stdin, setrecursionlimit
import queue

setrecursionlimit(10 ** 6)

def reverseQueue(inputQueue) :
if inputQueue.qsize()<=1:
return
data=inputQueue.get()
reverseQueue(inputQueue)
inputQueue.put(data)

'''-------------- Utility Functions --------------'''

def takeInput():

qu = queue.Queue()

for i in range(n) :
qu.put(values[i])

return qu

#main

while t > 0 :

qu = takeInput()
reverseQueue(qu)

while not qu.empty() :
print(qu.get(), end = " ")

print()

t -= 1``````
Prashant Marabe
Published On 10-Jan-2023
38 views
0 replies
Python_Soln
Interview problems
``````
from sys import stdin

#Following is the structure of the node class for a Singly Linked List
class Node :
def __init__(self, data) :
self.data = data
self.next = None

class Queue :
def __init__(self):
self.__tail = None
self.__size = 0
def getSize(self) :
return self.__size
#Implement the getSize() function

def isEmpty(self) :
return self.__size==0
#Implement the isEmpty() function
def enqueue(self, data) :
self.__size+=1
newNode = Node(data)
self.__tail=newNode
else:
self.__tail.next = newNode
self.__tail = newNode
def dequeue(self) :
if self.isEmpty():
return -1
self.__size = self.__size - 1
return ans
def front(self) :
if self.isEmpty():
return -1
#Implement the front() function

queue = Queue()

while q > 0 :
choice = int(inputs[0])
if choice == 1 :
data = int(inputs[1])
queue.enqueue(data)

elif choice == 2 :
print(queue.dequeue())

elif choice == 3 :
print(queue.front())

elif choice == 4 :
print(queue.getSize())

else :
if queue.isEmpty() :
print("true")
else :
print("false")

q -= 1``````
Prashant Marabe
Published On 10-Jan-2023
74 views
0 replies
Python_soln
Interview problems
``````import queue
from sys import stdin

class Stack :

def __init__(self) :
self.q1 = queue.Queue()
self.q2 = queue.Queue()

def getSize(self) :
return self.q1.qsize()

def isEmpty(self) :
return self.getSize() == 0

def push(self, data) :
self.q1.put(data)

def pop(self) :
if self.isEmpty() :
return -1

while self.q1.qsize() > 1 :
self.q2.put(self.q1.get())

ans = self.q1.get()

temp = self.q1
self.q1 = self.q2
self.q2 = temp

return ans

def top(self) :
if self.isEmpty() :
return -1

while self.q1.qsize() > 1 :
self.q2.put(self.q1.get())

ans = self.q1.get()
self.q2.put(ans)

temp = self.q1
self.q1 = self.q2
self.q2 = temp

return ans

#main

stack = Stack()

while q > 0 :

choice = int(inputs[0])

if choice == 1 :
data = int(inputs[1])
stack.push(data)

elif choice == 2 :
print(stack.pop())

elif choice == 3 :
print(stack.top())

elif choice == 4 :
print(stack.getSize())

else :
if stack.isEmpty() :
print("true")
else :
print("false")

q -= 1``````
Prashant Marabe
Published On 10-Jan-2023
120 views
0 replies
Python Solution
Interview problems
``````from sys import stdin

class Node :
def __init__(self, data) :
self.data = data
self.next = None

return None
fh,ft=None,None
else:
ft=ft.next
else:
ft=ft.next
else:
return fh

#Taking Input Using Fast I/O
def takeInput() :
tail = None

i = 0
while (i < len(datas)) and (datas[i] != -1) :
data = datas[i]
newNode = Node(data)

tail = newNode

else :
tail.next = newNode
tail = newNode

i += 1

while head is not None :

print()

# Main

while t > 0 :

t -= 1``````
Prashant Marabe
Published On 05-Jan-2023
60 views
0 replies
Python_Soln
Interview problems
``````from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 6)

class Node :
def __init__(self, data) :
self.data = data
self.next = None

#Taking Input Using Fast I/O
def takeInput() :
tail = None

i = 0
while (i < len(datas)) and (datas[i] != -1) :
data = datas[i]
newNode = Node(data)

tail = newNode

else :
tail.next = newNode
tail = newNode

i += 1

while head is not None :

print()

#main

while t > 0 :

t -= 1``````
Prashant Marabe
Published On 03-Jan-2023
49 views
0 replies
Python_Soln
Interview problems
``````
from sys import stdin, setrecursionlimit
setrecursionlimit(10**5)

class Node :
def __init__(self, data) :
self.data = data
self.next = None

return True
else:
return False

li1=[]
return li1
li2=[]
return li2

#Taking Input Using Fast I/O
def takeInput() :
tail = None

i = 0
while (i < len(datas)) and (datas[i] != -1) :
data = datas[i]
newNode = Node(data)

tail = newNode

else :
tail.next = newNode
tail = newNode

i += 1

while head is not None :

print()

#main

while t > 0 :

print('true')
else :
print('false')

t -= 1``````
Prashant Marabe
Published On 01-Jan-2023
69 views
0 replies
Python_Soln
Interview problems
``````

from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 6)

class Node :

def __init__(self, data) :

self.data = data

self.next = None

return

#Your code goes here

#Taking Input Using Fast I/O

def takeInput() :

tail = None

i = 0

while (i < len(datas)) and (datas[i] != -1) :

data = datas[i]

newNode = Node(data)

tail = newNode

else :

tail.next = newNode

tail = newNode

i += 1

while head is not None :

print()

#main

while t > 0 :