Geeksforgeeks

Error

×

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 | |

Handle | Score |

@ritiksethi21 | 1050 |

@aroranayan999 | 807 |

@RizulBansal | 685 |

@ashishtrehan002 | 538 |

@hemantgarg923 | 528 |

@simrangoyal | 526 |

@ronaldo77 | 520 |

@anishrajan | 505 |

@thanosagain | 505 |

@ssparteek470 | 495 |

@rahul2312 | 491 |

Complete Leaderboard |

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 <= 10^{3}

**Example:
Input:**

2

6

1 2 3 4 5 6

5

1 5 3 9 7

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.

Login to report an issue on this page.

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

Yes
Pairwise Consecutive Elements

...