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 EdgeScore(int[] edges) { | |
long[] deg = new long[edges.Length]; | |
long max = -1; | |
for(int i = 0; i < edges.Length; i++) | |
{ | |
deg[edges[i]]+=i; | |
max = Math.Max(max, deg[edges[i]]); | |
} | |
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 ArithmeticTriplets(int[] nums, int diff) { | |
var set = new HashSet<string>(); | |
int i = 0; | |
int n = nums.Length-1; | |
int c = 0; | |
while(i <= n-2) | |
{ |
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 LatestTimeCatchTheBus(int[] buses, int[] passengers, int capacity) { | |
PriorityQueue<int, int> qbus = new(); | |
PriorityQueue<int, int> qpass = new(); | |
HashSet<int> set = new(); | |
foreach(var bus in buses) qbus.Enqueue(bus, bus); | |
foreach(var p in passengers) | |
{ |
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
using System.Collections.Generic; | |
public class Solution { | |
public IList<IList<int>> Permute(int[] nums) { | |
IList<IList<int>> solution = new List<IList<int>>(); | |
Traverse(nums, new HashSet<int>(), new List<int>(), solution); | |
return solution; | |
} | |
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
function combinationSum(candidates: number[], target: number): number[][] { | |
let allStack: number[][] = []; | |
traverse(candidates, target, [], allStack, 0); | |
return allStack; | |
}; | |
function traverse(candidates: number[], target: number, currentStack: number[], allStack: number[][], startIter: number) { | |
if (target === 0) { | |
allStack.push([...currentStack]); |
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
using System; | |
public class Solution { | |
public void Rotate(int[][] matrix) { | |
for(int i = 0; i < matrix.Length/2; i++) | |
{ | |
for(int j = i; j < matrix[i].Length - 1 - i; j++) | |
{ | |
int b = matrix[j][matrix[i].Length-1-i]; |
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
using System.Text; | |
using System.Collections.Generic; | |
public class Solution { | |
public string Convert(string s, int numRows) { | |
StringBuilder sb = new StringBuilder(); | |
List<int> pillarIndexes = new List<int>(); | |
int i = 0; | |
int h = numRows - 1; |
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
using System.Text; | |
public class Solution { | |
public string CountAndSay(int n) { | |
if(n == 1) return "1"; | |
var previousSay = CountAndSay(n - 1); | |
StringBuilder sb = new StringBuilder(); | |
int runningOcc = 1; |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class Solution { | |
public bool IsValidSudoku(char[][] board) { | |
List<List<HashSet<int>>> sudokuSection = Enumerable.Range(1, 3) | |
.Select(x => Enumerable.Range(1, 3).Select(x1 => new HashSet<int>(9)).ToList()).ToList(); | |
List<HashSet<int>> rows = Enumerable.Range(1, 9).Select(x => new HashSet<int>(9)).ToList(); |
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
using System.Collections.Generic; | |
public class Solution { | |
public IList<IList<int>> ThreeSum(int[] nums) { | |
var tripletsCollection = new List<IList<int>>(nums.Length); | |
var tripletSet = new HashSet<string>(nums.Length); | |
var numOccurance = new Dictionary<int, HashSet<int>>(nums.Length); | |
for(int i = 0; i < nums.Length; i++) | |
AddNumOccurance(numOccurance, nums[i], i); |
NewerOlder