# Category: Data structures

#### Java Minimum Number of swaps required to sort an array

To find the minimum number of swaps required to make an array sorted, you can use the concept of selection sort. Here’s an example implementation in Java: public class MinimumSwaps…

#### Linked list find nth element from end

To find the nth node from the end of a linked list, you can use the two-pointer technique. Example implementation in Java: class ListNode { int val; ListNode next; ListNode(int…

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…

#### Graphs Introduction

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…

#### Remove a loop in a linked list

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…

#### Detect cycle in linked list

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…

#### Implement Stack using a linked list

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) {…

#### Remove duplicates from a linked list

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…

#### Java Valid Parentheses with out stack

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…

#### Java Left Rotate Array K Times

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…