DSA

Data structure & algorithm using swift language.

Check if string is rotated

[Question]: Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s. A shift on s consists of moving the leftmost character of s to the rightmost position. For example, if s = “abcde”, then it will be “bcdea” after one shift. Input: s = “abcde”, goal = “abced” Output: false

Check if string is rotated Read More »

Find largest odd Number/Sequence in String

[Question]: In integer string Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string “” if no odd integer exists. A substring is a contiguous sequence of characters within a string. Example 1: Input: num = “52” Output: “5” Explanation: The only non-empty substrings are “5”, “2”, and “52”. “5” is the only odd number input

Find largest odd Number/Sequence in String Read More »

 Remove Outermost Parentheses || String

[Question]: A valid parentheses string is either empty “”, “(” + A + “)”, or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, “”, “()”, “(())()”, and “(()(()))” are all valid parentheses strings. Return s after removing the outermost parentheses of every primitive string in the primitive decomposition of s. Example 1: Input: s = “(()())(())” Output: “()()()” Explanation: The input string

 Remove Outermost Parentheses || String Read More »