Consecutive Pairs In An Array

easy
1. Given a stack of integers of size N, your task is to complete the function pairWiseConsecutive()
  2. It checks whether numbers in the stack are pairwise consecutive or not. 
  3. 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. 
  4. The function should retain the original stack content.
  5. 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.    
  
  Example
  Input : stack = [4, 5, -2, -3, 11, 10, 5, 6, 20]
  Output : Yes
  Each of the pairs (4, 5), (-2, -3), (11, 10) and
  (5, 6) consists of consecutive numbers.

Input Format

The function takes a single argument as input, a stack object 's' of type int that contain the elements. For test cases the function will be called separately.

Output Format

A single line containing "Yes"(without quote) if the elements of the stack is pairwise consecutive, else print "No".

Constraints

1<=N<=103

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
6
1 2 3 4 5 6
Output
true
Previous
Checking Priority Queue Operation
Next
Making Jumps

Related Questions