10 Important Paytm Coding Interview Questions
Oct 03, 2024 14 Min Read 4003 Views
(Last Updated)
If you are in a rush to crack that Paytm coding Interview Questions round then here is a short pocketbook that you should go through. Make sure you practice all the 10 coding questions in here, (and study the related ones) because these are the most asked Paytm coding interview questions, say the interviewees!
Table of contents
- Top 10 Paytm Coding Interview Questions
- Given an integer number, convert it to a roman numeral.
- Given a string s, reverse the order of words.
- Sort an array of 0s, 1s and 2s
- Convert a Binary Tree into its Mirror Tree
- Remove duplicates from an unsorted linked list
- Write a function to get the Nth node in a Linked List
- Delete a node in a Doubly Linked List
- Delete all the nodes from the doubly linked list that are greater than a given value
- Interchange elements of the first and last rows in the matrix
- Write a function to print the ZigZag order traversal of a binary tree.
- More Paytm coding interview questions
Top 10 Paytm Coding Interview Questions
Coding comes in handy when you practise it several times. And one coding question can solve multiple related queries on the go. So do practise as many coding questions as you can!
Before diving into the next section, ensure you’re solid on full-stack development essentials like front-end frameworks, back-end technologies, and database management. If you are looking for a detailed Full Stack Development career program, you can join GUVI’s Full Stack Development Course with placement assistance. You will be able to master the MERN stack (MongoDB, Express.js, React, Node.js) and build real-life projects.
Additionally, if you would like to explore JavaScript through a self-paced course, try GUVI’s JavaScript certification course.
1. Given an integer number, convert it to a roman numeral.
Answer: A combination of some symbols represent Roman numerals.
Value | Symbol |
1 | I |
5 | V |
10 | X |
50 | L |
100 | C |
500 | D |
1000 | M |
Sample Input:
num: 10
Expected output:
“X”
Code: IntegerToRoman.java
public class IntegerToRoman
{
//method to convert integer to roman
//function that converts an integer to roman
public static String intToRoman(int number)
{
//creating an array of place values
String[] thousands = {“”, “M”, “MM”, “MMM”};
String[] hundreds = {“”, “C”, “CC”, “CCC”, “CD”, “D”, “DC”, “DCC”, “DCCC”, “CM”};
String[] tens = {“”, “X”, “XX”, “XXX”, “XL”, “L”, “LX”, “LXX”, “LXXX”, “XC”};
String[] units = {“”, “I”, “II”, “III”, “IV”, “V”, “VI”, “VII”, “VIII”, “IX”};
return thousands[number / 1000] + hundreds[(number % 1000) / 100] + tens[(number % 100) / 10] + units[number % 10];
}
public static void main(String args[])
{
//creating an array of integers to be converted into roman
int[] numbers = {13, 21, 38, 50, 190, 141, 117, 120, 125, 138, 149, 6, 712, 181, 197, 918, 199, 1100, 1101, 1248, 1253};
for (int number: numbers)
{
System.out.printf(“%4d -> %8s\n”, number, intToRoman(number));
}
}
}
Output:
2. Given a string s, reverse the order of words.
Sample Input
life is beautiful
enjoy it
live upto it
Expected Output
beautiful is life
it enjoy
it upto live
Code:
class Solution {
String reverseWords(String s) {
int numOfWords = 1;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) == ' ') {
numOfWords++;
}
}
String[] allWords = new String[numOfWords];
String currentWord = "";
int index = 0;
for(int i = 0; i < s.length(); i++) {
if(s.charAt(i) == ' ') {
allWords[index++] = currentWord;
currentWord = "";
} else {
currentWord += s.charAt(i);
}
}
allWords[index++] = currentWord;
String ans = "";
for(int i = index - 1; i > 0; i--) {
ans += allWords[i];
ans += ' ';
}
ans += allWords[0];
return ans;
}
}
3. Sort an array of 0s, 1s and 2s
Sample Input:
{0, 1, 2, 0, 1, 2}
Output:
{0, 0, 1, 1, 2, 2}
Code:
import java.io.*;
classcountzot{
// Sort the input array, the array is assumed to
// have values in {0, 1, 2}
static void sort 012(inta[], intarr_size){
int
lo =
0
;
int
hi = arr_size -
1
;
int
mid =
0
, temp =
0
;
// Iterate till all the elements
are sorted
while
(mid <= hi) {
switch
(a[mid]) {
// If the element is 0
case
0
: {
temp = a[lo];
a[lo] = a[mid];
a[mid] = temp;
lo++;
mid++;
break
;
}
// If the element is 1
case
1
:
mid++;
break
;
// If the element is 2
case
2
: {
temp = a[mid];
a[mid] = a[hi];
a[hi] = temp;
hi--;
break
;
}
}
}
}
/* Utility function to print array arr[] */
static void print Array(intarr[], intarr_size){
int
i;
for
(i =
0
; i < arr_size; i++)
System.out.print(arr[i] +
" "
);
System.out.println(
""
);
}
/*Driver function to check for above functions*/
public static void main(String[] args){
int
arr[] = {
0
,
1
,
1
,
0
,
1
,
2
,
1
,
2
,
0
,
0
,
0
,
1
};
int
arr_size = arr.length;
sort012(arr, arr_size);
printArray(arr, arr_size);
}
}
Practise more Paytm coding interview questions: Placement Preparation with GUVI
4. Convert a Binary Tree into its Mirror Tree
Code:
classNode { intdata; Node left, right; publicNode(intitem) { data = item; left = right = null; } } classBinaryTree { Node root; voidmirror() { root = mirror(root); } Node mirror(Node node) { if(node == null) returnnode; /* do the subtrees */ Node left = mirror(node.left); Node right = mirror(node.right); /* swap the left and right pointers */ node.left = right; node.right = left; returnnode; } voidinOrder() { inOrder(root); } /* Helper function to test mirror(). Given a binary search tree, print out its data elements in increasing sorted order.*/ voidinOrder(Node node){ if(node == null) return; inOrder(node.left); System.out.print(node.data + " "); inOrder(node.right); } /* testing for example nodes */ publicstaticvoidmain(String args[]){ /* creating a binary tree and entering the nodes */ BinaryTree tree = newBinaryTree(); tree.root = newNode(1); tree.root.left = newNode(2); tree.root.right = newNode(3); tree.root.left.left = newNode(4); tree.root.left.right = newNode(5); /* print inorder traversal of the input tree */ System.out.println(" Binary tree is"); tree.inOrder(); System.out.println(""); /* convert tree to its mirror */ tree.mirror(); /* print inorder traversal of the minor tree */ System.out.println(" Mirror tree is "); t ree.inOrder(); } } |
Output
Binary tree is 4 2 5 1 3 Mirror tree is 3 1 5 2 4
5. Remove duplicates from an unsorted linked list
Input:
linked list = 12->11->12->21->41->43->21
Output:
12->11->21->41->43.
Code:
// Java program to remove duplicates from unsorted// linked listclassLinkedList { static Node head; static class Node{ int data; Node next; Node(intd){ data = d; next = null; } } /* Function to remove duplicates from an unsorted linked list */ void remove_duplicates(){ Node ptr1 = null, ptr2 = null, dup = null; ptr1 = head; /* Pick elements one by one */ while(ptr1 != null&& ptr1.next != null) { ptr2 = ptr1; /* Compare the picked element with rest of the elements */ while(ptr2.next != null) { /* If duplicate then delete it */ if(ptr1.data == ptr2.next.data) { /* sequence of steps is important here */ ptr2.next = ptr2.next.next; System.gc(); } else/* This is tricky */{ ptr2 = ptr2.next; } } ptr1 = ptr1.next; } } voidprintList(Node node){ while(node != null){ System.out.print(node.data + " "); node = node.next; } } public static void main(String[] args){ LinkedList list = newLinkedList(); list.head = newNode(10); list.head.next = newNode(12); list.head.next.next = newNode(11); list.head.next.next.next = newNode(11); list.head.next.next.next.next = newNode(12); list.head.next.next.next.next.next = newNode(11); list.head.next.next.next.next.next.next= newNode(10); System.out.println("Linked List before removing duplicates:"); list.printList(head); list.remove_duplicates(); System.out.println("\n"); System.out.println("Linked List after removing duplicates:"); list.printList(head); } } |
Output
Linked list before removing duplicates 10 12 11 11 12 11 10 Linked list after removing duplicates 10 12 11
More articles related to Paytm coding interview questions: Interview Questions
6. Write a function to get the Nth node in a Linked List
Input: 5->10->15->20, index = 2 Output: 15 The node at index 2 is 15
// Java program to find n'th node in linked listclassNode{ intdata; Node next; Node(intd){ data = d; next = null; } } classLinkedList{ Node head; // the head of list /* Takes index as argument and return data at index*/ publicintGetNth(intindex){ Node current = head; intcount = 0; /* index of Node we are currently looking at */ while(current != null) { if(count == index) returncurrent.data; count++; current = current.next; } /* if we get to this line, the caller was asking for a non-existent element so we assert fail */ assert(false); return0; } /* Given a reference to the head of a list and an int, inserts a new Node on the front of the list. */ publicvoidpush(intnew_data) { /* 1. alloc the Node and put data*/ Node new_Node = newNode(new_data); /* 2. Make next of new Node as head */ new_Node.next = head; /* 3. Move the head to point to new Node */ head = new_Node; } /* Driver code*/ publicstaticvoidmain(String[] args) { /* Start with empty list */ LinkedList llist = newLinkedList(); /* Use push() to construct below list 1->12->1->4->1 */ llist.push(1); llist.push(4); llist.push(1); llist.push(12); llist.push(1); /* Check the count function */ System.out.println("Element at index 3 is "+ llist.GetNth(3)); } } |
Output
Element at index 3 is 4
7. Delete a node in a Doubly Linked List
Code:
// Java program to delete a node from // Doubly Linked List// Class for Doubly Linked ListpublicclassDLL { Node head; // head of list /* Doubly Linked list Node*/ classNode { intdata; Node prev; Node next; // Constructor to create a new node next and prev is by default initialized as null Node(intd) { data = d; } } // Adding a node at the front of the list publicvoidpush(intnew_data) { // 1. allocate node // 2. put in the data Node new_Node = newNode(new_data); // 3. Make next of new node as head and previous as NULL new_Node.next = head; new_Node.prev = null; // 4. change prev of head node to new node if(head != null) head.prev = new_Node; // 5. move the head to point to the new node head = new_Node; } // This function prints contents of linked list starting from the given node public void print list(Node node) { Node last = null; while(node != null) { System.out.print(node.data + " "); last = node; node = node.next; } System.out.println(); } // Function to delete a node in a Doubly Linked List. head_ref --> pointer to head node pointer. // del --> data of node to be deleted. void delete Node(Node del){ // Base case if(head == null|| del == null){ return; } // If node to be deleted is head node if(head == del) { head = del.next; } // Change next only if node to be deleted is NOT the last node if(del.next != null) { del.next.prev = del.prev; } // Change prev only if node to be deleted is NOT the first node if(del.prev != null) { del.prev.next = del.next; } // Finally, free the memory occupied by del return; } // Driver Code public static void main(String[] args){ // Start with the empty list DLL dll = newDLL(); // Insert 3. So linked list becomes 3->NULL dll.push(3); // Insert 6. So linked list becomes 6->3->NULL dll.push(6); // Insert 9. So linked list becomes 9->6->3->NULL dll.push(9); // Insert 12. So linked list becomes // 12->9->6->3->NULL dll.push(12); System.out.print("Original Linked list "); dll.printlist(dll.head); dll.deleteNode(dll.head); /*delete first node*/ dll.deleteNode(dll.head.next); /*delete middle node*/ dll.deleteNode(dll.head.next); /*delete last node*/ System.out.print("\nModified Linked list "); dll.printlist(dll.head); } } |
Output
Original Linked list 12 9 6 3 Modified Linked list 9
8. Delete all the nodes from the doubly linked list that are greater than a given value
Input: 20 31 6 3 11, X = 11
Output: 6 3 11
Code:
// Java implementation to delete all the nodes from the double linked list that are greater than the specified value xclassGFG{ // Node of the doubly linked list static class Node{ intdata; Node prev, next; }; // function to insert a node at the beginning of the Doubly Linked Liststatic Node push(Node head_ref, intnew_data){ // allocate node Node new_node = newNode(); // put in the data new_node.data = new_data; // since we are adding at the beginning, // prev is always null new_node.prev = null; // link the old list off the new node new_node.next = (head_ref); // change prev of head node to new node if((head_ref) != null) (head_ref).prev = new_node; // move the head to point to the new node (head_ref) = new_node; returnhead_ref; } // function to delete a node in a Doubly Linked List.// head_ref -. pointer to head node pointer.// del -. pointer to node to be deleted static Node deleteNode(Node head_ref, Node del){ // base case if(head_ref == null|| del == null) returnnull; // If node to be deleted is head node if(head_ref == del) head_ref = del.next; // Change next only if node to be deleted is NOT the last node if(del.next != null) del.next.prev = del.prev; // Change prev only if node to be deleted is NOT the first node if(del.prev != null) del.prev.next = del.next; returnhead_ref; } // function to delete all the nodes from the doubly linked list that are greater than the specified value x static Node deleteGreaterNodes(Node head_ref, intx){ Node ptr = head_ref; Node next; while(ptr != null){ next = ptr.next; // if true, delete node 'ptr' if(ptr.data > x){ deleteNode(head_ref, ptr); ptr = next; } returnhead_ref; } // function to print nodes in a given doubly linked list static void printList(Node head){ while(head != null) { System.out.print(head.data + " "); head = head.next; } } // Driver code public static void main(String args[]){ // start with the empty list Node head = null; // create the doubly linked list 10<.8<.4<.11<.9 head = push(head, 9); head = push(head, 11); head = push(head, 4); head = push(head, 8); head = push(head, 10); intx = 9; System.out.print( "Original List: "); printList(head); head=deleteGreaterNodes(head, x); System.out.print( "\nModified List: "); printList(head); } } |
Output
Original List: 10 8 4 11 9 Modified List: 8 4 9
9. Interchange elements of the first and last rows in the matrix
One of the most asked Paytm coding interview questions:
Input: 6 4 7 0 5
3 2 7 1 2
4 8 1 2 6
5 6 1 1 2
Output: 5 6 1 1 2
3 2 7 1 2
4 8 1 2 6
6 4 7 0 5
Code:
// Java code to swap the element of first and last row and display the result importjava.io.*; publicclassInterchange { static void inter changeFirstLast(intm[][]){ introws = m.length; // swapping of element between first and last rows for(inti = 0; i < m[0].length; i++) { intt = m[0][i]; m[0][i] = m[rows - 1][i]; m[rows - 1][i] = t; } } // Driver code public static void main(String args[]) throwsIOException { // input in the array intm[][] = { { 8, 9, 7, 6}, { 4, 7, 6, 5},{ 3, 2, 1, 8},{ 9, 9, 7, 7} }; // Function call interchangeFirstLast(m); // printing the interchanged matrix for(inti = 0; i < m.length; i++) { for(intj = 0; j < m[0].length; j++) System.out.print(m[i][j] + " "); System.out.println(); } } } |
Output
9 9 7 7 4 7 6 5 3 2 1 8 8 9 7 6
10. Write a function to print the ZigZag order traversal of a binary tree.
The zigzag order traversal for the below binary tree will be 1 3 2 7 6 5 4.
Code:
// Java implementation of a O(n) time method for Zigzag order traversal importjava.util.*; // Binary Tree node classNode{ intdata; Node leftChild; Node rightChild; Node(intdata){ this.data = data; } } classBinaryTree { Node rootNode; // function to print the zigzag traversal void print ZigZagTraversal() { // if null then return if(rootNode == null) { return; } // declare two stacks Stack<Node> currentLevel = newStack<>(); Stack<Node> nextLevel = newStack<>(); // push the root currentLevel.push(rootNode); booleanleftToRight = true; // check if stack is empty while(!currentLevel.isEmpty()) { // pop out of stack Node node = currentLevel.pop(); // print the data in it System.out.print(node.data + " "); // store data according to current order. if(leftToRight) { if(node.leftChild != null) { nextLevel.push(node.leftChild); } if(node.rightChild != null) { nextLevel.push(node.rightChild); } } else{ if(node.rightChild != null) { nextLevel.push(node.rightChild); } if(node.leftChild != null) { nextLevel.push(node.leftChild); } } if(currentLevel.isEmpty()) { leftToRight = !leftToRight; Stack<Node> temp = currentLevel; currentLevel = nextLevel; nextLevel = temp; } } } } publicclasszigZagTreeTraversal { // driver program to test the above function public static void main(String[] args){ BinaryTree tree = newBinaryTree(); tree.rootNode = newNode(1); tree.rootNode.leftChild = newNode(2); tree.rootNode.rightChild = newNode(3); tree.rootNode.leftChild.leftChild = newNode(7); tree.rootNode.leftChild.rightChild = newNode(6); tree.rootNode.rightChild.leftChild = newNode(5); tree.rootNode.rightChild.rightChild = newNode(4); System.out.println("ZigZag Order traversal of binary tree is"); tree.printZigZagTraversal();} } |
Output
ZigZag Order traversal of binary tree is 1 3 2 7 6 5 4
More Paytm coding interview questions
Definitely, there is more to this. Find the top Paytm coding interview questions on our award-winning practice platform- CODEKATA: where practice always makes you perfect!
For more Paytm coding interview-related questions click here: Placement Preparation with GUVI
Related blogs: Paytm coding interview questions
Kickstart your Full Stack Development journey by enrolling in GUVI’s certified Full Stack Development Course with placement assistance where you will master the MERN stack (MongoDB, Express.js, React, Node.js) and build interesting real-life projects. This program is crafted by our team of experts to help you upskill and assist you in placements.
Alternatively, if you want to explore JavaScript through a self-paced course, try GUVI’s JavaScript course.
Did you enjoy this article?