0% found this document useful (0 votes)
2 views6 pages

Questions

The document contains a comprehensive list of programming tasks in Java, organized into sets. Each task involves implementing various data structures and algorithms, such as queues, stacks, binary search trees, and dynamic programming solutions. The tasks cover a wide range of topics including searching, sorting, and manipulating data structures, as well as solving specific problems like finding triplets, unique paths, and subsequences.

Uploaded by

yasaswinisrit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Questions

The document contains a comprehensive list of programming tasks in Java, organized into sets. Each task involves implementing various data structures and algorithms, such as queues, stacks, binary search trees, and dynamic programming solutions. The tasks cover a wide range of topics including searching, sorting, and manipulating data structures, as well as solving specific problems like finding triplets, unique paths, and subsequences.

Uploaded by

yasaswinisrit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Questions:

Set-1

1a. Write a Java program to implement a queue using two stacks. Include operations to enqueue, dequeue, check if the queue is empty,
and display the queue contents.

1b. Write a Java program to find the minimum element in a rotated sorted array using a modified binary search.

Set-2

2a. Write a Java program that, for a given array, generates all (value, minimum) pairs for each rotation of the array and counts the total
number of such pairs where value > minimum.

2b. Write a Java program to implement a stack using two queues. Include operations for push, pop, top, display, and check if the stack is
empty.

Set-3

3a. Write a Java program to remove duplicates from an unsorted linked list using a HashSet.

3b. Write a Java program to search an element in a rotated sorted array using binary search. If found, return its index; otherwise, return -1.

Set-4

4a. Write a Java program to delete the nth node from the end of a singly linked list.

4b. Write a Java program to find the ceiling and floor of a given number x in a floating-point array with O(logn).

Set-5

5a. Write a Java program to find the element that occurs only once in a sorted array where every other element appears exactly twice.

5b. Write a Java program to reverse a singly linked list and display both the original and the reversed lists.

Set-6

6a) Two Sum (HashMap Approach)

Question:

Write a Java program to find the indices of two numbers in an array that add up to a given target using a HashMap.

6b) Search in Linked List (Iterative)

Question:

Write a Java program to perform an iterative search for a given element in a singly linked list.

6c) Search in Linked List (Recursive)

Question:

Write a Java program to perform a recursive search for a given element in a singly linked list.

Set-7

7a) Remove Duplicates and Sort (TreeSet)

Question:

Write a Java program to remove duplicates from an array and print the elements in sorted order using a TreeSet.

7b) Reverse a Queue (Recursion)

Question:

Write a Java program to reverse a queue using recursion.

reverse contents of queue using stack

Set-8
8a) Remove Consecutive Duplicates in String

Question:

Write a Java program to remove consecutive duplicate characters from a string

8b) Sort a Stack Using Another Stack

Question:

Write a Java program to sort a stack using only another stack as auxiliary space.

Set-9

9a) Equilibrium Index in Array

Question:

Write a Java program to find the equilibrium index of an array where the sum of elements on the left is equal to the sum on the right.

9b) Diameter of Binary Search Tree

Question:

Write a Java program to construct a Binary Search Tree (BST) and find its diameter (the length of the longest path between any two nodes).

Set-10

10a) Mirror of a BST

Question:

Write a Java program to create the mirror of a Binary Search Tree and print its inorder traversal before and after mirroring.

10b) Minimum Operations to Convert Arrays

Question:

Write a Java program to calculate the minimum number of operations to convert one array to another. An operation is defined as
incrementing or decrementing an element by 1.

Set-11

11a. Total Cost of Connections: Given a set of ropes with different lengths, calculate the total cost to connect all ropes. The cost to connect
two ropes is the sum of their lengths, and the total cost is the sum of all connection costs. (Use a priority queue/heap to solve this
efficiently.)

11b. Remove Half Nodes from a BST: Given a binary search tree, remove all half nodes. A half node is a node with only one child.
Implement this and print the inorder traversal of the tree before and after removing half nodes.

Set-12

12a. 1Print Left Nodes of a BST: Given a binary search tree (BST), print the data of all left child nodes.

12b. 1Product of Array Elements Without Division: Given an array, calculate a new array where each element is the product of all the
elements in the original array except the current element, without using division.

Set-13

13a.Assign Cookies to Children: Given an array representing children's greed factors and another array representing cookie sizes, determine
how many children can be satisfied with the available cookies. Each cookie can satisfy one child if its size is greater than or equal to the
child's greed factor.

13b.Width of a Binary Search Tree at a Given Level: Given a binary search tree, calculate the width of the tree at a specific level. The width
at a level is the number of nodes at that level.

Set-14

14a. Lemonade Stand Simulation: Implement a simulation where customers arrive with different payment amounts, and the lemonade
stand provides lemonade and change. The stand has a limited amount of change and can only serve a customer if it has enough change for
the transaction.1
14b. Height of a Binary Search Tree: Given a binary search tree, calculate the height of the tree. The height of a tree is the number of edges
on the longest path from the root to a leaf.

Set-15

15a. Equal Sum Among 3 Stacks: Given three stacks with positive integers, find the maximum equal sum that can be achieved by removing
elements from the stacks. You can only remove elements from the top of the stacks.

15b. Max Width of a Binary Search Tree: Given a binary search tree, find its maximum width. The width of a binary tree at any level is the
number of nodes at that level, and the maximum width is the highest width among all levels of the tree.

Set-16

16a. level order traversal in BST

16b.Knapsack problem (0/1 Knapsack using Dynamic Programming)

Set-17

17a.Count all root-to-leaf paths in a binary tree. [ A. No of routes from input n,m. (0,0) to (n,m). ]

17b.Breadth-first traversal of a binary search tree (BST).

Set-18

18a. Algorithm for finding the maximum subarray sum (kadane algorithm)..

18b. Inorder, Preorder, and Postorder Traversals of a binary tree.

Implement Binary search tree and all the Depth First Traversals(DFS)

Set-19

19a.Reverse characters of a string using two pointers technique.[ 1.reverse only string letters(ab-cd) op-(dc-ba)]

19b. Implement two stacks in one array (Dynamic implementation). [implement two stacks using an array(menu driven program with
push,pop,display,isempty,top for each stack)]

Set-20

20a. Find a triplet in an array such that the sum of two elements equals the third element.

20b. Implement Depth-First Search (DFS) using an adjacency list without recursion.

set-21

21a. Implement DFS Traversal in an Undirected Graph

Write a program that takes the number of vertices and edges of an undirected graph, followed by the edges themselves. Perform a DFS
traversal starting from node 0 and print the visited nodes.

21b. DFS Traversal in an Undirected Graph

Modify the program in question 1a to perform DFS traversal starting from any given node (not just node 0).

set-22

22a. Count the Number of Ways to Climb Stairs

Write a program that calculates the number of ways to climb a staircase where at each step, you can climb either 1, 2, or 3 stairs. The
program should take the number of stairs n as input.

22b. DFS Traversal in an Undirected Graph

Implement DFS traversal in an undirected graph, where the number of vertices and edges is provided, and the edges are entered in the
format u v. The traversal should start from node 0.

22b. dfs without recursion(dfs with adj matrix nonrecurrsion)

set-23
23a. Longest Common Subsequence

Write a program that computes the length of the longest common subsequence (LCS) of two strings. The program should take two strings
as input and output the length of their LCS.

23b. DFS Traversal in an Undirected Graph (Custom Start)

Implement a DFS traversal where the starting node for the traversal is provided by the user as input. The program should take the number
of vertices and edges as input, along with the edges, and start DFS from the specified node.

set-24

24a. Find Triplets with Sum Zero

Write a program to find all unique triplets in an array that sum to zero. The program should take the number of elements and the elements
of the array as input.

24b. BFS Traversal in an Undirected Graph

Implement BFS traversal in an undirected graph. The program should take the number of vertices, the number of edges, and the edges as
input, and it should start the BFS traversal from a specified node.

set-25

25a. Find Minimum Platforms for Trains

Write a program to find the minimum number of platforms required to accommodate a set of trains given their arrival and departure
times. The program should take the number of trains, along with their arrival and departure times, as input.

25b. BFS Traversal in an Undirected Graph (Custom Start)

Modify the BFS traversal program to allow the user to specify the starting node for the BFS traversal. The program should take the number
of vertices, the number of edges, and the edges as input, along with the starting node.

set-26

1a. Write a Java program to check if the parentheses in a given string are balanced.

1b. Implement a program that checks if the parentheses in a given string are balanced using a stack.

set-27

1a. Write a Java program to find all quadruplets in an array that sum to a given target.

1b. Implement a program to delete the middle element of a stack using recursion.

set-28

1a. Write a Java program to find the maximum element in a queue.

1b. Implement a stack using two queues and provide methods to push, pop, top, and check if the stack is empty.

set-29

1a. Write a Java program to find the number of unique paths in a grid with obstacles, where you can only move right or down.[using (dp)]

1b. Implement a program to reverse a queue using a stack.

set-30

1a. Write a Java program to remove duplicates from a given array.

1b. Implement a MinStack that supports push, pop, and retrieving the minimum element efficiently

minimum element in queue with O(1) time complexity.

set-31

1a. Write a Java program to find the missing term in a logarithmic sequence where each term is multiplied by a constant ratio. The
sequence will have one missing term.
Eg:{1,3,5,7,11}

o/p:9

1b. Write a Java program to implement a stack that supports retrieving the minimum element in constant time. Implement the push, pop,
and getMin operations.

Build a stack and find minimum element in a stack with Time Complexity O(1) and space complexity O(1)

set-32

1a. Write a Java program to find the intersection of two arrays in O(log n) time complexity using binary search.

1b. Write a Java program to check if a string is a palindrome using a stack and a queue.

set-33

1a. Write a Java program to find the intersection of two arrays using a HashSet.

1b. Write a Java program to check if a string is a palindrome using a stack and a queue.

set-34

1a. Write a Java program to implement a ternary search algorithm for finding a target element in a sorted array.

1b. Write a Java program to check if a linked list is a palindrome using a stack.

set-35

1a. Write a Java program to return a sorted array of squares of the elements from a given sorted array.

1b. Write a Java program to remove the Nth node from the end of a singly linked list.

Set-36

36a. Diameter of Binary Search Tree (BST)

36b. Insertion in BST and Diameter Calculation

Set-37

37a. Longest Increasing Subsequence (LIS)

37b. Longest Common Prefix Using Trie

Set-38

38a. Longest Bitonic Subsequence

38b. Count Substring Occurrences in Array of Strings

Set-39

39a. Given an array of N integers, find the length of the longest subsequence of a given sequence such that all elements of the
subsequence are sorted in strictly decreasing order.

Examples:

Input: arr[] = [15, 27, 14, 38, 63, 55, 46, 65, 85]

Output: 3

Explanation: The longest decreasing subsequence is {63, 55, 46}

Input: arr[] = {50, 3, 10, 7, 40, 80}

Output: 3

Explanation: The longest decreasing subsequence is {50, 10, 7}

39b. )Given an array of strings arr[], the task is to sort the array of strings according to the frequency of each string, in ascending order. If
two elements have the same frequency, then they are sorted into lexicographical order
Examples:

Input: arr[] = {“Geeks”, “for”, “Geeks”}

Output: {“for”, “Geeks”}

Explanation:

As the string “Geeks” has a frequency of 2 in the given array,

Hence, the position of the string “Geeks” will be 2

Input: arr[] = {“abc”, “pqr”, “pqr”, “abc”}

Output: {“abc”, “pqr”}

Explanation:

As both the strings have the same frequency, the array is sorted in the lexicographical order.

Set-40

40a. A buy and sell stocks with k transaction fee

40b. count half nodes in BST (ITERATIVE and RECURSIVE )

Set-41

41a. Maximum Profit from Stock Prices

41 a:sum of sub arrays (kadane algorithm)

B:bst find right view of tree

You might also like