This file contains hidden or 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 Solution { | |
public int kConcatenationMaxSum(int[] arr, int k) { | |
//case 1 when k==1 | |
if(k==1) | |
return kadanes(arr); | |
long sum=0; | |
for(int ele:arr) | |
sum+=ele; | |
This file contains hidden or 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 BST { | |
public int numTrees(int n) { | |
int[] arr = new int[20]; | |
arr[0] = 1; | |
arr[1] = 1; | |
int cnt = 0; | |
for (int i = 2; i <= n; i++) { |
This file contains hidden or 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.HashMap; | |
import java.util.Map; | |
public class Codec { | |
// Encodes a URL to a shortened URL. | |
private final static String prefix = "http://tinyurl.com/"; | |
public static Map<String, String> map = new HashMap<>(); | |
public String encode(String longUrl) { | |
Integer hashcode = longUrl.hashCode(); |
This file contains hidden or 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 TicTacToe { | |
public boolean validTicTacToe(String[] board) { | |
// count O and X | |
int cntX = 0; | |
int cntO = 0; | |
for (String str: board) { | |
for (char ch: str.toCharArray()) { | |
if (ch=='X') cntX++; |
This file contains hidden or 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 Solution { | |
public boolean isRobotBounded(String instructions) { | |
boolean answer = false; // the robot is set to leave the circle at first | |
char[] arr = instructions.toCharArray(); | |
int idx = 0; | |
int dir = 0; |
This file contains hidden or 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 Solution { | |
public int solution(int n, int[] lost, int[] reserve) { | |
int[] numbers = new int[n+2]; | |
for (int i : lost) numbers[i]--; | |
for (int i : reserve) numbers[i]++; | |
for (int i = 1; i < numbers.length-1; i++) { |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.