Balanced Brackets
Function Name: isBracketBalanced
Description
Write a function `isBracketBalanced` which checks whether a given string has balanced brackets.
The function takes a single string parameter where each character is either a standard opening or closing bracket ('(', ')', '{', '}', '[' or ']').
It should return `true` if the brackets in the string are balanced, meaning that each opening bracket has a corresponding closing bracket and the brackets are properly nested.
Return `false` if the string is empty, contains any other characters, or the brackets are not balanced.
Requirements
- The function should handle the three types of brackets: round '()', square '[]', and curly '{}'.
- Brackets are considered balanced if each opening bracket is matched by its corresponding closing bracket and the pairs are well nested.
- If a closing bracket appears before its corresponding opening bracket, or if any type of bracket is unmatched, the string is unbalanced.
- Ignore any characters that are not brackets.
- Optimize the function for readability and efficiency.
Examples
Given a string '(){}[]', `isBracketBalanced` should return `true`.Given a string '([{}])', `isBracketBalanced` should return `true`.Given a string '(]', `isBracketBalanced` should return `false`.Given a string '({[)]', `isBracketBalanced` should return `false`.Given a string 'abc', `isBracketBalanced` should return `false`.
Links
Duplicate Number Finder
Sat Nov 16 2024
Write a function 'findDuplicate' that takes an array of integers. The array contains integers in the range 1 to n (inclusive), with one integer appearing exactly twice. Your task is to find and return the duplicate integer.
Subarray Sum Equals K
Mon Nov 18 2024
Write a function called subarraySum that finds the total number of continuous subarrays whose sum equals to an integer k.The function should take an array of integers and the integer k as parameters.Return the count of such subarrays.