Skip to content

Instantly share code, notes, and snippets.

public class Solution {
public int solve(int A, int[][] B) {
ArrayList<Integer>[] graph = new ArrayList[A+1]; //A+1 because vertex are from 1 to A
for(int i=0;i<=A;i++){ //make graph
graph[i] = new ArrayList<>();
}
for(int i=0;i<B.length;i++){
int v1 = B[i][0];
int v2 = B[i][1];
graph[v1].add(v2);
class Student{
private String name;
private String phone;
private String age;
public static StudentBuilder getStudentBuilder(){ //to return StudentBuilder object
return new StudentBuilder();
}
public void print(){
class DBC{
static int a = 10;
private static DBC dbc;
private DBC(){}
public static DBC getInstance(){ //not thread safe
if(dbc == null){
dbc = new DBC();
}
return dbc;
}
import java.util.*;
class Player{
String name;
int currentPosition;
Player(String name, int currentPosition){
this.name = name;
this.currentPosition = currentPosition;
}
}
import java.util.*;
enum TransportMode{
CAR,
BIKE,
WALK
}
//-----------------------------------------
interface PathStrategy{
public void calculatePath(String from, String to);
}
import java.util.*;
interface PaymentSuccessEventSubscriber{//has common method called notify
void notify(int order_id);
}
class EmailService implements PaymentSuccessEventSubscriber{
public void notify(int order_id){
sendEmail(order_id);
}
public void sendEmail(int order_id){
interface Icecream{
int getPrice();
void printComposition();
}
class ChocoWafer implements Icecream{ //make a ChocoWafer class
private Icecream icecream; //already made cone if any
private int price = 20;
ChocoWafer(){} //if no cone till now
import java.util.*;
enum BulletType { //type of bullets available
FIVE_MM,
SEVEN_MM,
NINE_MM,
}
//-------------
class Bullet{ //intrinsic properties
int weight;
interface PaymentApi{ //Iterface for payments apis
boolean startTransaction(int transactionId);
boolean checkCompletion(int transactionId);
}
//---------------------
//Make individual adapters to connect
class PayUAdapter implements PaymentApi{ //Adapter to connect
PayUApi api = new PayUApi();
import java.util.*;
enum PageType{
A4,
A3,
A5
}
//----------------------------
class NoteBook{
private PageType pageType; //attributes