Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6379
@blackshadows 6329
@mb1973 5358
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3357
@KshamaGupta 3318
Complete Leaderboard
Pairwise Consecutive Elements
Basic Accuracy: 38.58% Submissions: 7544 Points: 1

Given a stack of integers of size N, your task is to complete the function pairWiseConsecutive(), that checks whether numbers in the stack are pairwise consecutive or not. The pairs can be increasing or decreasing, and if the stack has an odd number of elements, the element at the top is left out of a pair. The function should retain the original stack content.

Only following standard operations are allowed on stack.

  • push(X): Enter a element X on top of stack.
  • pop(): Removes top element of the stack.
  • empty(): To check if stack is empty.

Input Format:
The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains n denoting the number of elements to be inserted into the stack. The second line contains the elements to be inserted into the stack.

Output Format:
For each
testcase, in a new line, print "Yes"(without quote) if the elements of the stack is pairwise consecutive, else print "No".

Your Task:
This is a function problem. You only need to complete the function pairWiseConsecutive that takes a stack as an argument and returns true if the stack is found to be pairwise consecutive, else it returns false. The printing is done by the driver code.

Constraints:
1 < =T <= 100
1 < =N <= 103

Example:
Input:

2
6
1 2 3 4 5 6
5
1 5 3 9 7
Output:
Yes

No

Explanation:
Testcase1: The number of elements are even and they are pairwise consecutive so we print Yes.
Testcase2: The number of elements are odd so we remove the top element and check for pairwise consecutive. It is not so we print No.

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Pairwise Consecutive Elements

Output Window