Every element in an array of integers points to a relative location from the current element. Precisely, if A[k] = m, the jump from k should land at k+A[k]=k+m.
Write a function
int arrayJmp(int[] A);
that returns the number of jumps until the pointer jumps out of the array when starting from the firstelement.
For example:
The pointer's 1st jump is from 0 to 2, 2nd jump from 2 to 3, 3rd jump from 3 to 4, 4th jump from 4 to 7, but 7 is out of the array. The number of jumps until the pointer jumps out of the array is 4.
Return -1 if the sequence of jumps never ends.
❏
Write a function
int nesting(string S);
which given a string S made of characters ( and ) returns 1if S is properly nested, 0 otherwise.
In precise terms, a string is propetly nested if it has one of the following forms:
- empty,
- (S), where S is properly nested,
- ST, where both S and T are properly nested.
For example, given the string
your function should return 1, and for the string
your function should return 0.