This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Player{ | |
String name; | |
int currentPosition; | |
Player(String name, int currentPosition){ | |
this.name = name; | |
this.currentPosition = currentPosition; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
enum TransportMode{ | |
CAR, | |
BIKE, | |
WALK | |
} | |
//----------------------------------------- | |
interface PathStrategy{ | |
public void calculatePath(String from, String to); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
enum BulletType { //type of bullets available | |
FIVE_MM, | |
SEVEN_MM, | |
NINE_MM, | |
} | |
//------------- | |
class Bullet{ //intrinsic properties | |
int weight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
enum PageType{ | |
A4, | |
A3, | |
A5 | |
} | |
//---------------------------- | |
class NoteBook{ | |
private PageType pageType; //attributes |