Answered step by step
Verified Expert Solution
Question
1 Approved Answer
write a code that solves the following problem : the answer code can be in c++ or java or python Problem#9 1) In this problem
write a code that solves the following problem :
the answer code can be in c++ or java or python
Problem#9 1) In this problem you are given two type of query 1. Insert an integer to the list. 2. Given an integer x, you're about to find an integer k which represent x's index if the list is sorted in ascending order. Note that in this problem we will use 1-based indexing. As the problem title suggest, this problem intended to be solved using O(log (n)) for both insertion and getting X's index Input The first line contains an integer Q, which denotes how many queries that follows. The next Q lines will be one of the type queries which follow this format: 1 x means insert x to the list 2 x means find x's index if the list is sorted in ascending order. Output For each query type 2, print a line containing an integer as the answer or print"-1" no quotes if the requested number does not exist in the current list Input Example: 10 1 100 174 2 100 2 70 1 152 121 133 2 100 221 21 Output: 2-141-1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started