└── Binary Search concepts in c++.cpp /Binary Search concepts in c++.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution { 5 | public: 6 | int binarysearch(vector &arr, int k) { 7 | int low = 0; 8 | int high = arr.size()-1; 9 | while(low<=high) 10 | { 11 | int mid = (low+high)/2; 12 | if(arr[mid]>k) 13 | { 14 | high = mid-1; 15 | } 16 | else if(arr[mid]> t; 32 | while (t--) { 33 | int k; 34 | cin >> k; 35 | vector arr; 36 | string input; 37 | cin.ignore(); 38 | getline(cin, input); 39 | stringstream ss(input); 40 | int number; 41 | while (ss >> number) { 42 | arr.push_back(number); 43 | } 44 | Solution ob; 45 | int res = ob.binarysearch(arr, k); 46 | cout << res << endl; 47 | } 48 | return 0; 49 | } 50 | --------------------------------------------------------------------------------