electicode
HomeCoursesResourcesProblemsNational OlympiadContestsHall of Fame
...

Electicode will start hosting weekly contests with prizes soon! Subscribe to ElecticodeChannel telegram for news about contests and free courses.

Subscribe →

electicode Platform

Explore our collection of comprehensive courses designed to help you navigate life's challenges and opportunities.

Login to Get StartedJoin community →
binary_search.cpp
main.cpp
#include <bits/stdc++.h>
using namespace std;

// Find first position where check() is true
int binary_search(int lo, int hi) {
    while (lo < hi) {
        int mid = lo + (hi - lo) / 2;
        if (check(mid)) hi = mid;
        else lo = mid + 1;
    }
    return lo;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    return 0;
}

Platform

Everything you need to master competitive programming.

Learn

Master algorithms & data structures

Comprehensive lessons covering everything from basic arrays to advanced graph algorithms, segment trees, and dynamic programming.

Esc
1
2
3
4
5
6
7
8
9
0
-
=
⌫
Tab
Q
W
E
R
T
Y
U
I
O
P
[
]
\
Caps
A
S
D
F
G
H
J
K
L
;
'
Enter
Shift
Z
X
C
V
B
N
M
,
.
/
Shift
Ctrl
Fn
Alt
⌘
⌘
Alt
←
↓
→

Practice

Solve curated problems

Hundreds of hand-picked problems ranging from beginner to advanced, each with detailed editorials and multiple solution approaches.

e
AC
IOI
ICPC
USACO

Compete

Join contests

Participate in regular contests and compete with programmers from around the world.

Track

Monitor your progress

Detailed analytics and statistics to track your improvement over time.

+99

Community

Learn from experts

Access detailed editorials and solutions from experienced competitive programmers.

© 2026 Electicode. All rights reserved.