Array 1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Array 1

can someone pls give me the idea to write the code for the below problem? I will upload the code shortly. pls correct any mistakes. thanks. Given two arrays of integers output the smallest number in the first array not present in the second one. Input Specification: The first line contains the size Nl of the first array. Next line give the contents of the first array. Next line contains the size N2 of the second array. Next line give the contents of the second array. Output Format: Output must be a single number which is the smallest number occurring in the first array that does not occur in the second. In case there is no such number, output NO. Variable Constraints: The sizes of the arrays are smaller than 20. Each array entry is an integer which fits an int data type. Example: Input: 3 2 3 4 4 1 3 5 7 1 3 5 7 Output: 2 Input 1 1 2 1 2 Output NO

26th Sep 2018, 4:19 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
1 Answer
0
Sort both arrays. Then pick first value from first array and check if it is lower than first in second. If smaller you got answer. Else go up in second array till you find same value or get bigger. Same value forces to drop selected value from first array and pick next.
28th Apr 2019, 5:48 AM
Dima Sl
Dima Sl - avatar