Posts

Showing posts with the label #hashmap

Strings - Backspace String Compare using JAVA Stack

Question: Given two Strings S and T, return true if they equal when both are typed out any "#" will be treated as backspace. input - S -> ab#c, T -> az#c output - True Constraints need to ask because solution may change according to given constraints Question: What happens when 2 or multiple "#" appear besides each other? Answer: Delete same number of values before 1st "#". Ex- ab## -> "" Question: What happen to "#" when there is no character to remove? Answer: It deletes nothing. Ex- a###b -> "b" Question: Are two empty Strings equals each other? Answer: Ex- S -> a#b#c#, T -> c#. Both returns empty string and output will be true. Question: Does case sensitivity matters? Answer: Yes. Ex- A is different from a. S -> ab#c, T -> Az#c. Output - False Solution using JAVA language. BruteForce Approach - This is simple approach, We are using JAVA Stack here,...

Arrays - Two Sum

Question: Find a pair of index from given array where sum of numbers present at those indices is equal to given target number? input [4,2,5,8,9,6] target 7 output [1,2] Constraints need to ask because solution may change according to given constraints Question: If the given array only contains positive numbers or negative can be present? Answer: Only Positive numbers. Question: What would be output, If target number is not sum of any pair present in array? Answer: null Question: What will be output if only one integer present in given array, because question asked for pair of numbers? Answer: null Question: What is the output when given array is empty? Answer: null Question: Is there any duplicate number present in array? Answer: No Question: If multiple pair can have target sum, what will be output? Answer: First pair you get.