From e49366ea3c7fec7d168a3ab16b445ef9a18b9820 Mon Sep 17 00:00:00 2001
From: Pallavi Jadhav <39557017+pallavijadhav31@users.noreply.github.com>
Date: Fri, 2 Oct 2020 19:44:03 +0530
Subject: [PATCH] String based Problem Solved Questions Using Stack

https://www.hackerrank.com/challenges/reduced-string/problem
---
 .../Stack/Super_Reduced_String.java           | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 Practice Problems/Stack/Super_Reduced_String.java

diff --git a/Practice Problems/Stack/Super_Reduced_String.java b/Practice Problems/Stack/Super_Reduced_String.java
new file mode 100644
index 0000000..ce97754
--- /dev/null
+++ b/Practice Problems/Stack/Super_Reduced_String.java	
@@ -0,0 +1,47 @@
+/*Steve has a string of lowercase characters in range ascii[‘a’..’z’]. He wants to reduce the string to its shortest length by doing a series of operations. 
+In each operation he selects a pair of adjacent lowercase letters that match, and he deletes them. For instance, the string aab could be shortened to b in one operation.
+Steve’s task is to delete as many characters as possible using this method and print the resulting string. If the final string is empty, print Empty String
+
+Function Description
+Complete the superReducedString function in the editor below. It should return the super reduced string or Empty String if the final string is empty.
+superReducedString has the following parameter(s):a string to reduce
+
+Input Format
+A single string,s.
+
+Output Format
+If the final string is empty, print Empty String; otherwise, print the final non-reducible string.
+*/
+
+
+public class Solution {
+
+    //superReducedString function below.
+    static String superReducedString(String s) {
+        String st1="";
+        Stack<Character> stack = new Stack<>();
+        int i=0;
+        char ch;
+        while(i<s.length()){
+            char c=s.charAt(i);
+            if(stack.empty()){
+                stack.push(c);
+                i++;}
+            else if (stack.peek() == c){
+                stack.pop();
+                i++;} 
+            else{
+                stack.push(c);
+                i++;}
+                }
+        if(!stack.empty()){
+            while(!stack.empty()){
+                ch = stack.pop();
+                st1 = ch + st1;}
+        return st1;
+        }
+        else{
+            return"Empty String";
+        }
+    }
+}