Stack Problems
Stack is part of Collection in Java, it is a Interface which is based on Stack Data Structure. It follows the principle of LIFO that is Last in First Out.
25. How to Add Elements in Stack Collection in Java?
Input: stack = [10, 20, 30, 40, 50] ele = 100 pos = 2 Output: [10 , 20 , 100 , 30 , 40 , 50] Explanation: Add element (ele) in the stack at the position (pos).
26. Calculate weight of parenthesis based on the given conditions.
Input: S = “(()(()))” Output: 6 Explanation: () = 1 , then (()) =2 ()(()) = 1+2 = 3 (()(())) = 2*3 = 6 To check the rules refer to the article mentioned below.
27. Check If it is Possible to Convert Binary String into Unary String
Choose two adjacent characters, such that both are 1’s or 0’s. Then invert them, Formally, if both are 0’s then into 1’s or vice-versa. If we are able to convert every element either to all 1 or all 0 then the answer will be Yes else No. Input: N = 6, S = “110110” Output: YES Explanation: The operations are performed as: Invert 0,1 -> S = 000110 Invert 4,5 -> S = 000000
Java Collection Exercise
The Java Collection framework is a fundamental part of the Java programming language, It covers a major part of Java and acts as a prerequisite for many Advanced Java Topics. However, programmers often find it difficult to find a platform to Practice Java Online.
Take a look at our Java Collection Exercise that contains Java Collection Practice Problems to practice and to develop your Java Programming skills. Our Java Collection Practice Exercise will cover all the topics from Basic to Advanced, from ArrayList to Priority Queue. So, let’s dive in and sharpen our Java Collection skills together!
Table of Content
- Basic Program
- ArrayList Problems
- LinkedList Problems
- HashMap Problems
- HashSet Problems
- Stack Problems
- Queue Problems
- Priority Queue Problems