Sourav Sarkar

Sourav Sarkar

2 Articles Published

Articles by Sourav Sarkar

2 articles

Length of longest balanced parentheses prefix using Java

Sourav Sarkar
Sourav Sarkar
Updated on 07-Nov-2024 258 Views

In this article we will explore how we can find the length of longest balanced parentheses prefix using java , first we will understand the problem with some examples then we learn two different approaches to find it. Problem Statement Here, we will be given a string with parentheses and we need to find the length of balanced parentheses set from the string i.e. for every open parentheses "(" if there is a close parentheses ")", then we call it balanced. Prefix defines the first balanced set from the string, let the parenthesis set '(())()' we consider only '(())' Input ...

Read More

Delete middle element of a stack in Java

Sourav Sarkar
Sourav Sarkar
Updated on 01-Nov-2024 553 Views

In order to delete the middle element of a stack, then first we need to remove the elements above the middle element. After removing the middle element, we restore the elements above it to maintain the original sequence. We can achieve this using a recursive approach, as explained step-by-step below. We cannot delete the middle element of the stack directly because, according to the stack property, we can perform only push and pop operations on the top of the stack. Steps to Delete the Middle Element of a Stack Step 1: Determine the Position of the Middle Element, First ...

Read More
Showing 1–2 of 2 articles
« Prev 1 Next »
Advertisements