Skip to content

Plug-and-play Java templates for competitive programming: data structures (Union‑Find, Segment/Fenwick Trees), algorithms (BFS, DFS, Dijkstra, Kruskal, LIS, geometry), string hashing, fast I/O, and utilities. Boost contest coding efficiency—star ⭐ if you find it helpful!

Notifications You must be signed in to change notification settings

Gosling-dude/Java-Templates-for-CP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Competitive Programming in Java

⭐ If this repository helped you even a little, consider giving it a star!


This repository contains essential data structures and algorithms implemented in Java for competitive programming.

🔗 I'm SumitXorY / sumit_chauhan on coding platforms:
📘 Codeforces | 🍛 CodeChef

Feel free to use the codes — and if you find any bugs, don’t hesitate to report them!


📂 Contents

🧱 Data Structures
📌 Algorithms
🧵 Strings
🧮 Math

🧪 Miscellaneous


⚡ Fast I/O for Java: Template

Inspired by uwi, this I/O template greatly improves Java input/output speed for contests.

🔧 Highlights

  • Avoids slow Scanner and BufferedReader.
  • No more TLE due to I/O after switching to this.
  • Write your logic inside solve()main() calls it.

📘 Template Documentation

🔹 Input Methods

int x = ni();             // next int
long y = nl();            // next long
double d = nd();          // next double
String s = ns();          // next string
char c = nc();            // next char
int[] arr = na(n);        // array of size n
char[][] grid = nm(n, m); // character matrix

🔹 Output Methods

pn(obj); // println
p(obj);  // print

🔹 Utilities

int maxVal = max(arr);   // max from array
int minVal = min(arr);   // min from array
int g = gcd(x, y);       // gcd of two numbers

Includes a custom Pair class supporting hashing and sorting — usable in HashSets, HashMaps, and TreeMaps.

About

Plug-and-play Java templates for competitive programming: data structures (Union‑Find, Segment/Fenwick Trees), algorithms (BFS, DFS, Dijkstra, Kruskal, LIS, geometry), string hashing, fast I/O, and utilities. Boost contest coding efficiency—star ⭐ if you find it helpful!

Resources

Stars

Watchers

Forks

Languages