category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

Apartments, Two pointers, Sorting, Binary search, easy.

Implementation ```cpp int n, m, k; cin >> n >> m >> k; std ::vector arr(n), brr(m); for (auto &i : arr) cin >> i; for (auto &i : brr) cin >> i; int ans = 0; sort((arr).begin(), (arr).end()); sort((brr).begin(), (brr).end()); int i = 0; int j = 0; while (i < n and j < m) { int diff = abs(brr[j] - arr[i]); if (brr[j] < arr[i]) { if (diff <= k) { ans++; i++, j++; } else { j++; } } else { if (diff <= k) { ans++; i++, j++; } else { i++; } } } cout << ans << '\n'; ``` </details>
- Binary search approach - Maintain a mulitset of apartments. - so that we may apply `erase`, `lower_bound` in `logn` - binary search over apartments, for the user's choice. - Make sure to choose smallest apartment that is fitting in user's choice. - Implementation (will be added soon)