Knowee
Questions
Features
Study Tools

Given an array, you have to find the floor of a number x. The floor of a number x is nothing but the largest number in the array less than or equal to x.Input FormatThe first line of input contains the N - the size of the array. The next line contains N integers, the elements of the array. The next line contains Q - number of queries. Each of the next Q lines contains a single integer X, for which you have to find the floor of X in the given array.Output FormatFor each query, print the floor of X, separated by a new line. If the floor is not found, print the value of "INT_MIN".Constraints30 points1 <= N <= 1051 <= Q <= 102-108 <= ar[i] <= 10870 points1 <= N <= 1051 <= Q <= 105-108 <= ar[i] <= 108ExampleInput6-6 10 -1 20 15 55-1108-10-4Output-1105-2147483648-6

Question

Given an array, you have to find the floor of a number x. The floor of a number x is nothing but the largest number in the array less than or equal to x.Input FormatThe first line of input contains the N - the size of the array. The next line contains N integers, the elements of the array. The next line contains Q - number of queries. Each of the next Q lines contains a single integer X, for which you have to find the floor of X in the given array.Output FormatFor each query, print the floor of X, separated by a new line. If the floor is not found, print the value of "INT_MIN".Constraints30 points1 <= N <= 1051 <= Q <= 102-108 <= ar[i] <= 10870 points1 <= N <= 1051 <= Q <= 105-108 <= ar[i] <= 108ExampleInput6-6 10 -1 20 15 55-1108-10-4Output-1105-2147483648-6

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

This problem is asking you to find the largest number in an array that is less than or equal to a given number. Here's a step-by-step guide on how to solve it:

  1. Parse the input. The first line gives you the size of the array. The second line contains the array elements. The third line gives you the number of queries. Each subsequent line contains a number for which you need to find the floor in the array.

  2. For each query, iterate through the array to find the largest number that is less than or equal to the given number.

  3. If such a number is found, print it. If no such number is found (i.e., all numbers in the array are greater than the given number), print "INT_MIN".

Here's a Python solution for the problem:

N = int(input())
arr = list(map(int, input().

This problem has been solved

Similar Questions

Given an array, you have to find the ceil of a number x. The ceil of a number x is nothing but the smallest number in the array greater than or equal to x.Input FormatThe first line of input contains the N-size of the array. The next line contains N integers, the elements of the array. The next line contains Q - number of queries. Each of the next Q lines contains a single integer X, for which you have to find the ceil of X in the given array.Output FormatFor each query, print the ceil of X, separated by a new line. If ceil is not found, print the value of "INT_MAXConstraints30 points1 <= N <=1051 <= Q <=102-108 <= ar[i] <=10870 points1 <= N <=1051 <= Q <=105-108 <= ar[i] <=108

Given an array, you have to find the frequency of a number x.Input FormatThe first line of input contains N - size of the array. The next line contains N integers, the elements of the array. The next line contains Q - number of queries. Each of the next Q lines contains a single integer X, for which you have to find the frequency of X in the given array.Output FormatFor each query, print the frequency of X, separated by a new line.Constraints20 points1 <= N <= 1051 <= Q <= 102-108 <= ar[i] <= 10830 points1 <= N <= 1051 <= Q <= 105-108 <= ar[i] <= 10850 points1 <= N <= 1051 <= Q <= 105-108 <= ar[i] <= 108ExampleInput9-6 10 -1 20 -1 15 5 -1 155-11081520Output31021

aran wants to develop a program that uses linear search to find the majority element in an array, which is an element appearing more than n-2 times, where n is the size of the array. The program should input the size of the array and its elements. Display the majority element if found, and indicate if no majority element is present in the array.Help Saran in developing the program.Input format :The first line of input consists of an integer n, representing the number of elements in the array.The second line consists of n space-separated integers, representing the array elements.Output format :The output prints an integer representing the majority element.If no such element is found, print "No majority element found."

arrayfindProblem DescriptionRar the cat hates counting and wants you to help. This time, he has an array of numbers not more than 1000000 length long. He also has Q queries. Each query will consist of a number, x. You are supposed to tell him how many numbers in the array are above and below x.InputThe first line of input consists of L, the length of the array.The second line of input consists of L integers, space separated. You may assume they all fit into a 32bit signed integer.The third line of input consists of Q, the number of queries. Q will be not more than 10000.The following Q line of input consists of one number each, x. You may assume they all fit into a 32bit signed integer.OutputFor each query, output how many numbers is smaller than it and how many numbers are greater than it (See Below).Sample Input105 8 7 2 4 3 7 9 1 957010036Sample OutputSmaller: 5, Greater: 3Smaller: 0, Greater: 10Smaller: 10, Greater: 0Smaller: 2, Greater: 7Smaller: 5, Greater: 5

Largest KYou are given an array 𝐴A of size 𝑁N.Find the largest integer 𝐾K such that there exists a subsequence 𝑆S of length 𝐾K where 𝐾K is divisible by the number of distinct elements in 𝑆S.Input FormatThe first line contains a single integer 𝑇T, denoting the number of test cases.The first line of each test case contains a positive integer 𝑁N, the length of array 𝐴A.The second line contains 𝑁N space-separated integers, 𝐴1,𝐴2,…,𝐴𝑁A 1​ ,A 2​ ,…,A N​ −− denoting the array 𝐴A.Output FormatFor each test case, output the largest valid 𝐾K.Constraints1≤𝑇≤1041≤T≤10 4 1≤𝐴𝑖≤𝑁≤2⋅1051≤A i​ ≤N≤2⋅10 5 The sum of 𝑁N over all test cases won't exceed 2⋅1052⋅10 5 .Sample 1:InputOutput322 141 2 1 351 5 3 2 4235

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.