My Roadmap
My Setups - cpp
java
python
🔥​
- C++
- Java
- Python
#include<bits/stdc++.h>
using namespace std;
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
return 0;
}
Use
using
instead oftypedef
, for example usingll = long long;
.Use
auto
to increase readability and decrease code size.Use
ios::sync_with_stdio(false);
andcin.tie(nullptr);
for faster Input/Output usingcin
/cout
.Use builtin functions starting with
__builtin
.- GCD and LCM are available in ***C++17*** under `gcd` and `lcm`.
Use C++11 for-each style for loops for
(auto& elem : vec)
.Use C++17 binding style like for
(auto& [key, val] : dic)
andauto [x, y] = myPoint;
Use C++17 template argument deduction
pair p{1, 2.5};
instead ofpair<int, double> p{1, 2.5};
.If you have a lot of nested loops and conditions, refactor! You probably should be using functions.
Never use
goto!
But be brave enough to usegoto
when you want to break from several nested loops (in case you just can't refactor it)!Some websites like codeforces use the flag
-DONLINE_JUDGE
to compile your code, this means that you can remove yourcerr
s or your debug functions automatically or redirect input/output to file instead of stdin/stdout, etc.
import java.io.*;
import java.util.*;
public class Main {
//BeginCodeSnip{Kattio}
static class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
// standard input
public Kattio() { this(System.in, System.out); }
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(new FileWriter(problemName + ".out"));
r = new BufferedReader(new FileReader(problemName + ".in"));
}
// returns null if no more input
public String next() {
try {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(r.readLine());
return st.nextToken();
} catch (Exception e) { }
return null;
}
public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}
//EndCodeSnip
// add methods
// add methods
public static void main(String[] args) {
Kattio io = new Kattio();
// long x = io.nextLong(); String str = io.next(); int a = io.nextInt();
// io.println(x); /* For System.out.println() */ or // io.print(x);
// Code
io.close(); // make sure to include this line -- closes io and flushes the output
}
}
Explanatory Template same as above
​
/** Simple yet moderately fast I/O routines.
*
* Example usage:
*
* Kattio io = new Kattio();
*
* while (io.hasMoreTokens()) {
* int n = io.nextInt();
* double d = io.nextDouble();
* double ans = d*n;
*
* io.println("Answer: " + ans);
* }
*
* io.close();
*
*
* Some notes:
*
* - When done, you should always do io.close() or io.flush() on the
* Kattio-instance, otherwise, you may lose output.
*
* - The nextInt(), nextDouble(), and nextLong() methods will throw an
* exception if there is no more data in the input, so it is generally
* a good idea to use hasMoreTokens() to check for end-of-file.
*
* @author: Kattis
*/
import java.util.*;
import java.io.*;
class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st = new StringTokenizer("");
private String token;
// standard input
public Kattio() {
this(System.in, System.out);
}
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(new FileWriter(problemName + ".out"));
r = new BufferedReader(new FileReader(problemName + ".in"));
}
private String peek() {
if (token == null)
try {
while (!st.hasMoreTokens()) {
String line = r.readLine();
if (line == null)
return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
public boolean hasMoreTokens() {
return peek() != null;
}
private String next() {
String ans = peek();
token = null;
return ans;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
public class Main {
static Kattio io = new Kattio();
public static void main(String[] args) {
int a = io.nextInt();
int b = io.nextInt();
int c = io.nextInt();
io.print("sum is ");
io.println(a + b + c);
io.close(); // make sure to include this line -- closes io and flushes the output
}
}
def hello_world():
print 'Hello, world!'
Debugging C++ Template​
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
int main() {
#ifndef ONLINE_JUDGE
freopen("Error.txt", "w", stderr);
#endif
// Code
}
Visualisations​
Cpp
Documentations:​
- https://www.cplusplus.com/reference/ ~
Beginner Friendly
- https://en.cppreference.com/w/cpp/header ~
Better
Advanced
- https://devdocs.io/cpp/ ~ Based on
cppreference.com
- https://docs.microsoft.com/en-us/cpp/standard-library/cpp-standard-library-header-files?view=msvc-160
- https://www.learncpp.com/
- https://github.com/aitjcize/cppman ~
Offline Documentation for Terminal
- https://www.boost.org/ ~
Boost C++
Java
Documentations:​
Java SE 14
https://docs.oracle.com/en/java/javase/14/docs/api/java.base/module-summary.htmlJava SE 15
https://docs.oracle.com/en/java/javase/15/docs/api/java.base/module-summary.htmlJava SE 16
https://docs.oracle.com/en/java/javase/16/docs/api/java.base/module-summary.htmlJava 8 Technotes
https://docs.oracle.com/javase/8/docs/technotes/guides/Java 8 Tutorials
https://docs.oracle.com/javase/tutorial/
Learning DSA​
Resources I am Following:​
- Apna college DSA
- Coding Blogs Interview Prep
- Coding Blogs Interview Prep
- Coding Ninja Competitive
- Coding Blocks Competitive
- CodeForces Edu: https://codeforces.com/edu/course/2
- https://www.codechef.com/cptutorials
- https://www.codechef.com/getting-started
- https://www.codechef.com/ioi/basics
Other Resources​
- Codeforces Blogs
- InterviewBit Blogs
Must Use Resources to Learn:​
- java acad__
- HackerEarth Notes / Code Monk
- InterviewBit Materials
- Educative-> Grokking the Coding InterviewBit
- CP- Algorithms
- GeeksforGeeks
- TopCoder Blogs
- CodeForces Blogs
- CodeChef Resources
- algoExperts
- Atcoder Begineer and Regular Editorials
TopicWise:​
Dynamic Programming​
https://leetcode.com/discuss/general-discussion/458695/dynamic-programming-patterns
https://www.topcoder.com/thrive/articles/Dynamic%20Programming:%20From%20Novice%20to%20Advanced
https://leetcode.com/discuss/general-discussion/458695/dynamic-programming-patterns/439810
https://leetcode.com/discuss/study-guide/1437879/dynamic-programming-patterns
https://leetcode.com/discuss/general-discussion/458695/dynamic-programming-patterns
https://leetcode.com/discuss/general-discussion/458695/dynamic-programming-patterns/439810
https://leetcode.com/discuss/study-guide/1437879/dynamic-programming-patterns
https://leetcode.com/discuss/general-discussion/458695/dynamic-programming-patterns
Guides:​
- The Guide
- hSkill Roadmap
- Codechef Certificate: https://www.codechef.com/certification/data-structures-and-algorithms/prepare
- Resources Links:
- https://techprep.org/ by Facebook
Websites to prepare for Aptitude/ Reasoning:​
- FreshersWorld
- Puzzlefry
- IndiaBIX
- AmbitionBox
- Fresherslive
...
- Internshala
- Careers
- U dg
Caution Section
Hackathons​
- Major League Hacking
- DevPost
- Hackathons International
- Hackaday
- DevFolio
- Hack Club
- HackaList
- AngelHack
- Hackathon IO
- https://www.githubhackathon.com/#hackathon
- https://github.com/github/hackathons