Balanced Brackets
Function Name: isBracketSequenceBalanced
Description
Implement a function to check if a given string containing only '(', ')', '[', ']', '{', and '}' has balanced brackets. The brackets must close in the correct order, '(', ')', '{', '}', and '[', ']', where each opening bracket has a corresponding closing bracket. A bracket sequence is considered balanced if each opening bracket is followed by the corresponding closing bracket and the order of brackets is correct.
Requirements
- The function should take a single parameter, a string containing only the characters '(', ')', '[', ']', '{', and '}'.
- The function should return a boolean value: true if the bracket sequence is balanced, false otherwise.
- The function should handle an empty string, which is considered balanced.
- Do not use regular expressions to solve this challenge.
- Usage of stack-based approach is recommended.
Examples
isBracketSequenceBalanced('(){}[]') should return trueisBracketSequenceBalanced('([{}])') should return trueisBracketSequenceBalanced('(}') should return falseisBracketSequenceBalanced('[(])') should return falseisBracketSequenceBalanced('') should return true
Links
Odd-Even List Separation
Fri Jul 26 2024
Write a function 'separateOddEven' that takes an array of integers as a parameter. The function should separate the odd and even numbers from the array and return an object with two array properties: 'odd' and 'even'.The 'odd' array should include all the odd numbers from the input array in the same order they appeared, and the 'even' array should include all the even numbers in the same order they appeared.The function should not use any built-in sort methods and should iterate over the input array only once.
Matrix Diagonal Summation
Sun Jul 28 2024
Write a function that accepts a two-dimensional square matrix (an array of arrays) and returns the absolute difference between the sums of its diagonals.For example, given a square matrix:[[1, 2, 3], [4, 5, 6], [7, 8, 9]]The left-to-right diagonal sums up to 1 + 5 + 9 = 15. The right-to-left diagonal sums up to 3 + 5 + 7 = 15. The function should return the absolute difference which is 0 in this case.