Update appNew update is available. Click here to update.
About
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
yellow-spark
3122
Level
5 (Champion)
Community stats
Discussions
0
Upvotes
2
Know more
168
Total problems solved
140
Easy
26
Moderate
2
Hard
0
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

0 days

Longest streak:

2 days

Less

More

Achievements
4
Ronin
Topics
Math
Backtracking
+ 2 more
8
Samurai
Topics
Linked List
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):
	#Your code goes here
    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():
    n = int(stdin.readline().strip())

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

    preOrder = list(map(int, stdin.readline().strip().split(" ")))
    inOrder = list(map(int, stdin.readline().strip().split(" ")))

    return preOrder, inOrder, n


# Main
preOrder, inOrder, n = takeInput()
root = buildTree(preOrder, inOrder)
printLevelWise(root)
profile
Prashant Marabe
Published On 19-Jan-2023
48 views
0 replies
0 upvotes
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):
	#Your code goes here
    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():
    levelOrder = list(map(int, stdin.readline().strip().split(" ")))
    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)
profile
Prashant Marabe
Published On 16-Jan-2023
64 views
0 replies
1 upvotes
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():
    levelOrder = list(map(int, stdin.readline().strip().split(" ")))
    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)



profile
Prashant Marabe
Published On 16-Jan-2023
96 views
0 replies
0 upvotes
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():
    n = int(stdin.readline().strip())

    qu = queue.Queue()
    values = list(map(int, stdin.readline().strip().split()))

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

    return qu


#main
t = int(stdin.readline().strip())

while t > 0 :
    
    qu = takeInput()
    reverseQueue(qu)
    
    while not qu.empty() :
        print(qu.get(), end = " ")
        
    print()
    
    t -= 1
profile
Prashant Marabe
Published On 10-Jan-2023
38 views
0 replies
0 upvotes
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.__head = None
        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)
        if self.__head is None:
            self.__head = newNode
            self.__tail=newNode
        else:
            self.__tail.next = newNode
            self.__tail = newNode
    def dequeue(self) :
        if self.isEmpty():
            return -1
        ans = self.__head.data
        self.__head = self.__head.next
        self.__size = self.__size - 1
        return ans
    def front(self) :
        if self.isEmpty():
            return -1
        return self.__head.data
        #Implement the front() function
        
q = int(stdin.readline().strip())
queue = Queue()

while q > 0 :
    inputs = stdin.readline().strip().split(" ")
    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
profile
Prashant Marabe
Published On 10-Jan-2023
74 views
0 replies
0 upvotes
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
q = int(stdin.readline().strip())

stack = Stack()

while q > 0 :

    inputs = stdin.readline().strip().split(" ")
    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
profile
Prashant Marabe
Published On 10-Jan-2023
120 views
0 replies
2 upvotes
Python Solution
Interview problems
from sys import stdin

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



def mergeTwoSortedLinkedLists(head1, head2):
    if (head1 is None) and (head2 is None):
    # Write your code here
        return None
    if (head1 is None) and (head2 is not None):
        return head2
    if (head2 is None) and (head1 is not None):
        return head1
    fh,ft=None,None
    if head1.data<head2.data:
        fh,ft=head1,head1
        head1=head1.next
    else:
        fh,ft=head2,head2
        head2=head2.next
    while (head1 is not None) and (head2 is not None):
        if head1.data<head2.data:
            ft.next=head1
            ft=ft.next
            head1=head1.next
        else:
            ft.next=head2
            ft=ft.next
            head2=head2.next
    if head2 is None:
        ft.next=head1
    else:
        ft.next=head2
    return fh

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

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

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

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head


def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()


# Main
t = int(stdin.readline().rstrip())

while t > 0 :

    head1 = takeInput()
    head2 = takeInput()

    newHead = mergeTwoSortedLinkedLists(head1, head2)
    printLinkedList(newHead)

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

#Following is the Node class already written for the Linked List
class Node :
    def __init__(self, data) :
        self.data = data
        self.next = None



def reverseLinkedListRec(head) :
	#Your code goes here
    if head is None or head.next is None:
        return head
    smallHead = reverseLinkedListRec(head.next)
    tail=head.next
    tail.next = head
    head.next = None

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

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

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

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head




def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()


#main
t = int(stdin.readline().rstrip())

while t > 0 :
    
    head = takeInput()

    newHead = reverseLinkedListRec(head)
    printLinkedList(newHead)

    t -= 1
profile
Prashant Marabe
Published On 03-Jan-2023
49 views
0 replies
0 upvotes
Python_Soln
Interview problems

from sys import stdin, setrecursionlimit
setrecursionlimit(10**5)

#Following is the Node class already written for the Linked List
class Node :
    def __init__(self, data) :
        self.data = data
        self.next = None


def isPalindrome(head) :
    if forwardll(head) == reversell(head):
        return True
    else:
        return False
    
    
def forwardll(head):
    li1=[]
    while head is not None:
        li1.append(head.data)
        head=head.next
    return li1
def reversell(head):
    li2=[]
    while head is not None:
        li2.insert(0, head.data)
        head=head.next
    return li2


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

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

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

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head


#to print the linked list 
def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()


#main
t = int(stdin.readline().rstrip())

while t > 0 :
    
    head = takeInput()
    
    if isPalindrome(head) :
        print('true')
    else :
        print('false')
        
    t -= 1
profile
Prashant Marabe
Published On 01-Jan-2023
69 views
0 replies
0 upvotes
Python_Soln
Interview problems



from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 6)




#Following is the Node class already written for the Linked List

class Node :

    def __init__(self, data) :

        self.data = data

        self.next = None







def printReverse(head) :

    if(head == None):

        return 

    printReverse(head.next)

    print(head.data,end=" ")

    #Your code goes here




#Taking Input Using Fast I/O

def takeInput() :

    head = None

    tail = None




    datas = list(map(int, stdin.readline().rstrip().split(" ")))




    i = 0

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

        data = datas[i]

        newNode = Node(data)




        if head is None :

            head = newNode

            tail = newNode




        else :

            tail.next = newNode

            tail = newNode




        i += 1




    return head





#to print the linked list 

def printLinkedList(head) :




    while head is not None :

        print(head.data, end = " ")

        head = head.next




    print()





#main

t = int(stdin.readline().rstrip())




while t > 0 :




    head = takeInput()

    printReverse(head)

    print()




    t -= 1
profile
Prashant Marabe
Published On 01-Jan-2023
78 views
0 replies
0 upvotes