First q : Write an algorithm to determine if a given string contains a balanced

WRITE MY ESSAY

First q :
Write an algorithm to determine if a given string contains a balanced

First q :
Write an algorithm to determine if a given string contains a balanced sequence of parentheses.
Input
The input consists of a string containing “(” or “)” only.
Output
Print an Integer representing the count of balanced pairs if the string is balanced. Else print -1 Second q2:
Write an algorithm to find the number of occurrences of needle in a given positive number haystack.
Input
The first line of the input consists of an integer needle, representing a digit.
The second line consists of an integer haystack, representing the positive number.
Output
Print an integer representing the number of occurrences of needle in haystack,
Constraints
0 ≤ needle ≤ 9
0 ≤ haystack ≤ 99999999
Example
Input:
2
123228
Output:
3
Dont use chatgpt at all I can use it!!!

WRITE MY ESSAY

admin Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *