India’s Best Job Seekers and Training Platform Forums Data Structure You are required to collect N numbers from a bag. Initially, the bag is empty..

  • You are required to collect N numbers from a bag. Initially, the bag is empty..

     Akash  updated 11 months, 3 weeks ago 1 Member · 1 Post
  • Akash 

    Administrator
    at

    You are required to collect N numbers from a bag. Initially, the bag is empty. Whenever you put a number X in the bag, then the owner of the bag asks the question.
    The questions are as follows:
    . What is the greatest integer that is smaller than X and present inside the bag?
    . What is the smallest number that is greater than X and present inside the bag?
    If you answer both the questions correctly, then you can put X inside the bag. Your task is to answers the questions that are asked by the owner of the bag. If no such numbers exist in the bag print -1.
    Example:
    5 (Number of elements in the bag)
    1
    4
    2
    3
    7
    output:
    -1 -1
    1 -1
    1 4
    2 4
    4 -1

Log in to reply.

Original Post
0 of 0 posts June 2018
Now
KodNest Training New Batch is starting on 02nd November 2020. Attend one week free demo classes.Register Now

New Report

Close