Balanced Parentheses Checker
Function Name: isValidParentheses
Description
Write a function that takes a string containing only parentheses characters '(', ')', '{', '}', '[' and ']', and determines if the input string is valid.
An input string is valid if:
- Open brackets are closed by the same type of brackets.
- Open brackets are closed in the correct order.
No extra characters are allowed in the input string.
Requirements
- The function must accept a single parameter: a string containing only the characters '(', ')', '{', '}', '[' and ']'.
- The function must return a boolean indicating whether the input string is valid.
- The function must handle strings of any length, including empty strings.
Examples
`isValidParentheses('()')` should return `true`.`isValidParentheses('()[]{}')` should return `true`.`isValidParentheses('(]')` should return `false`.`isValidParentheses('([)]')` should return `false`.`isValidParentheses('{[]}')` should return `true`.
Links
LinkedListCycleDetector
Tue Nov 05 2024
Write a function named 'hasCycle' that takes the head of a singly linked list as its single parameter.The function should determine whether the linked list contains a cycle, which is a situation where nodes in the list form a loop.A singly linked list is said to have a cycle if, by continuously following the next pointers, a node is encountered that has already been visited.The function should return a boolean value: true if the list contains a cycle, and false otherwise.
Run-Length Encoding
Thu Nov 07 2024
Implement a function to perform run-length encoding on a string.Run-length encoding is a basic form of data compression, where sequences of the same data value (in this case, characters) are stored as a single data value and a count.This function should take a string as input and return the encoded string.The output string should be formed by concatenating each unique character with the number of times it appears consecutively in the input string.The function should be case-sensitive ('A' is considered different from 'a').If a character occurs only once consecutively, it should be followed by the number '1'.The function must handle empty strings gracefully by returning an empty string.