#include <iostream>
#include <vector>
// Function to find the index and check existence
void findOrInsertPosition(const std::vector<int>& arr, int N) {
auto it = std::lower_bound(arr.begin(), arr.end(), N);
int index = it - arr.begin();
if (it != arr.end() && *it == N)
std::cout << "Found at index: " << index << std::endl;
else
std::cout << "Index where " << N << " would be: " << index << std::endl;
}
int main() {
std::vector<int> arr = {1, 3, 5, 7, 8, 9, 12, 15}; // Sorted array
int N = 6; // Element to find or insert
findOrInsertPosition(arr, N);
findOrInsertPosition(arr, 9);
}
/*
run:
Index where 6 would be: 3
Found at index: 5
*/