Java – Valid Parentheses
This is one of the most common datastructure interview questions and to validate parenthesis. Examples of valid parentheses: (()){}{} Examples of Invalid parentheses : ({) or {(((()))) Problem: Given a…
This is one of the most common datastructure interview questions and to validate parenthesis. Examples of valid parentheses: (()){}{} Examples of Invalid parentheses : ({) or {(((()))) Problem: Given a…
In this post, we will see Valid Parenthesis with stack. This solution uses a counter to keep track of the balance of parentheses. Whenever an opening parenthesis is encountered, the…
Problem : Given of size ‘n’ and a values ‘k’ around which we need to right rotate the array. Array: [1,2,3,4,5,6,7], K = 3 Rorate1: 7,1,2,3,4,5,6 Rotate2: 6,7,1,2,3,4,5 Rotate3: 5,6,7,1,2,3,4 Solution…
Problem: Given array of size ‘n’ and left rotate k times Input : [1,2,3,4,5,6,7], K=3 Left Rotate 1: 2,3,4,5,6,7,1 Left Rotate 2: 3,4,5,6,7,1,2 Left Rotate 3: 4,5,6,7,1,2,3 Solution: Reverse the…
In this, we will see java code to remove duplicates from linked list Java Code: class LinkedList { static class Node { int data; Node next; Node(int d) { data…
In this tutorial, we will see Java program to implement a stack using a linked list class Stack { static class Node { int data; Node next; Node(int d) {…
In this tutorial, we will see Java program to detect a cycle in a linked list The LinkedList class defines a Node inner class that represents a node in the…
In this tutorial, we will see java program to remove a loop in linked list In this code,If a loop is detected, we use another pointer to find the starting…
Graphs are an important data structure in computer science and are used to model many real-world scenarios. Here are some common interview questions related to graphs: Graph A graph is…
A linked list is a linear data structure that consists of nodes, each containing a value and a reference to the next node in the list. The first node is…