public class Solution {
public double MaxAverageRatio(int[][] classes, int extraStudents) {
var pq = new PriorityQueue<int[], double>(Comparer<double>.Create((x, y) => y.CompareTo(x)));
foreach (var currentClass in classes) {
var a = (double) currentClass[0];
var b = (double) currentClass[1];
var res = ((a+1)/(b+1)) - (a/b);
pq.Enqueue(currentClass, res);
}
for (var i = 0; i < extraStudents; i++) {
var currentClass = pq.Dequeue();
currentClass[0] += 1;
currentClass[1] += 1;
var a = (double) currentClass[0];
var b = (double) currentClass[1];
var res = ((a+1)/(b+1)) - (a/b);
pq.Enqueue(currentClass, res);
}
double result = 0;
while (pq.TryDequeue(out int[] item, out double priority)) {
result += (double)item[0]/item[1];
}
return result / classes.Length;
}
}https://leetcode.com/problems/maximum-average-pass-ratio/?envType=daily-question&envId=2025-09-01 - daily question
topics: #priority_queue #greedy
level: #medium
LeetCode
Maximum Average Pass Ratio - LeetCode
Can you solve this real interview question? Maximum Average Pass Ratio - There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [passi, totali]. You know beforehand…
🏆5💔3🔥2🍓1💋1
public class Solution {
public int FindClosest(int x, int y, int z) => Math.Abs(x-z) == Math.Abs(y-z) ? 0 : (Math.Abs(x-z) < Math.Abs(y-z) ? 1 : 2);
}https://leetcode.com/problems/find-closest-person/?envType=daily-question&envId=2025-09-04 - daily question
topics: #math
level: #easy
probably the easiest easy
LeetCode
Find Closest Person - LeetCode
Can you solve this real interview question? Find Closest Person - You are given three integers x, y, and z, representing the positions of three people on a number line:
* x is the position of Person 1.
* y is the position of Person 2.
* z is the position…
* x is the position of Person 1.
* y is the position of Person 2.
* z is the position…
🔥3🦄2🍓1💋1
public class Solution {
public string SortVowels(string s) {
var vowelsSet = new HashSet<char>{'A','a','E','e','I','i','O','o','U','u'};
var vowels = new List<char>();
for (var i = 0; i < s.Length; i++) {
if (vowelsSet.Contains(s[i])) {
vowels.Add(s[i]);
}
}
vowels.Sort();
var j = 0;
char[] result = s.ToCharArray();
for (var i = 0; i < s.Length; i++) {
if (vowelsSet.Contains(s[i])) {
result[i] = vowels[j];
j++;
}
}
return new string(result);
}
}https://leetcode.com/problems/sort-vowels-in-a-string/?envType=daily-question&envId=2025-09-11 - daily question
topics: #string #sorting
level: #medium
TC: O(NlogN)
SC: O(N)
LeetCode
Sort Vowels in a String - LeetCode
Can you solve this real interview question? Sort Vowels in a String - Given a 0-indexed string s, permute s to get a new string t such that:
* All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such…
* All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such…
🔥4🐳2💋1
public class Solution {
public bool DoesAliceWin(string s) {
var set = new HashSet<char>{'a','e','i','o','u'};
var count = 0;
foreach (char r in s) {
if (set.Contains(r)) {
count++;
}
}
return count == 0 ? false : true;
}
}https://leetcode.com/problems/vowels-game-in-a-string/?envType=daily-question&envId=2025-09-12 - daily question
topics: #string #brainteaser
level: #medium
LeetCode
Vowels Game in a String - LeetCode
Can you solve this real interview question? Vowels Game in a String - Alice and Bob are playing a game on a string.
You are given a string s, Alice and Bob will take turns playing the following game where Alice starts first:
* On Alice's turn, she has…
You are given a string s, Alice and Bob will take turns playing the following game where Alice starts first:
* On Alice's turn, she has…
❤3🔥3💋1
type Router struct {
limit int
queue [][3]int
storage map[[3]int]bool
destTimestampMap map[int][]int
}
func Constructor(memoryLimit int) Router {
return Router{
limit: memoryLimit,
queue: make([][3]int, 0, memoryLimit),
storage: make(map[[3]int]bool),
destTimestampMap: map[int][]int{},
}
}
func (this *Router) AddPacket(source int, destination int, timestamp int) bool {
packet := [3]int{source, destination, timestamp}
if this.storage[packet] {
return false
}
if len(this.queue) >= this.limit {
first := this.queue[0]
this.queue = this.queue[1:]
delete(this.storage, first)
timestamps := this.destTimestampMap[first[1]]
if len(timestamps) > 0 && first[2] == timestamps[0] {
this.destTimestampMap[first[1]] = timestamps[1:]
}
}
this.queue = append(this.queue, packet)
this.destTimestampMap[destination] = append(this.destTimestampMap[destination], timestamp)
this.storage[packet] = true
return true
}
func (this *Router) ForwardPacket() []int {
if len(this.queue) == 0 {
return []int{}
}
first := this.queue[0]
this.queue = this.queue[1:]
timestamps := this.destTimestampMap[first[1]]
if len(timestamps) > 0 && first[2] == timestamps[0] {
this.destTimestampMap[first[1]] = this.destTimestampMap[first[1]][1:]
}
delete(this.storage, [3]int{first[0], first[1], first[2]})
return []int{first[0], first[1], first[2]}
}
func (this *Router) GetCount(destination int, startTime int, endTime int) int {
timestamps, ok := this.destTimestampMap[destination]
if !ok {
return 0
}
return search(timestamps, endTime+1)-search(timestamps, startTime)
}
func search(times []int, val int) int {
l, r := 0, len(times)-1
for l <= r {
mid := l + (r-l)/2
if times[mid] >= val {
r = mid - 1
} else {
l = mid + 1
}
}
return l
}https://leetcode.com/problems/implement-router/description/
topics: #array #queue #design_system #binary_search
level: #medium
LeetCode
Implement Router - LeetCode
Can you solve this real interview question? Implement Router - Design a data structure that can efficiently manage data packets in a network router. Each data packet consists of the following attributes:
* source: A unique identifier for the machine that…
* source: A unique identifier for the machine that…
🔥5❤4💋2
public class Solution {
public ListNode MergeInBetween(ListNode list1, int a, int b, ListNode list2) {
ListNode pointA = null;
ListNode pointB = null;
var curr = list1;
var i = 0;
while(curr != null) {
if (i == a-1) pointA = curr;
if (i == b+1) {
pointB = curr;
break;
}
curr = curr.next;
i++;
}
pointA.next = list2;
while(list2 != null & list2.next != null) {
list2 = list2.next;
}
list2.next = pointB;
return list1;
}
}https://leetcode.com/problems/merge-in-between-linked-lists/ -i've started solving linked list problem, because i had been solving some linked list problems in go, thats why i've decided to solve in c#
topics: #linked_list
level: #medium
LeetCode
Merge In Between Linked Lists - LeetCode
Can you solve this real interview question? Merge In Between Linked Lists - You are given two linked lists: list1 and list2 of sizes n and m respectively.
Remove list1's nodes from the ath node to the bth node, and put list2 in their place.
The blue edges…
Remove list1's nodes from the ath node to the bth node, and put list2 in their place.
The blue edges…
❤4🔥2💔1💋1
public class Solution {
public int TriangularSum(int[] nums) {
var m = nums.Length;
for (var i = 0; i < nums.Length-1; i++) {
for (var j = 0; j < m-1; j++) {
nums[j] = (nums[j]+nums[j+1])%10;
}
m--;
}
return nums[0];
}
}https://leetcode.com/problems/find-triangular-sum-of-an-array/description/?envType=daily-question&envId=2025-09-30 - daily question
topics: #array #math #simulation
level: #medium
LeetCode
Find Triangular Sum of an Array - LeetCode
Can you solve this real interview question? Find Triangular Sum of an Array - You are given a 0-indexed integer array nums, where nums[i] is a digit between 0 and 9 (inclusive).
The triangular sum of nums is the value of the only element present in nums…
The triangular sum of nums is the value of the only element present in nums…
🔥3❤2👍1💋1
func getIntersectionNode(headA, headB *ListNode) *ListNode {
dymmyA := &ListNode{
Next: headA,
}
dymmyB := &ListNode{
Next: headB,
}
i := 0
for headA != nil {
headA = headA.Next
i++
}
j := 0
for headB != nil {
headB = headB.Next
j++
}
var (
f *ListNode
s *ListNode
)
k := 0
if j < i {
f = dymmyA.Next
s = dymmyB.Next
k = i-j
} else {
s = dymmyA.Next
f = dymmyB.Next
k = j-i
}
for f != nil && s != nil {
if s == f {
return s
}
if k > 0 {
f = f.Next
k--
} else {
f = f.Next
s = s.Next
}
}
return nil
}https://leetcode.com/problems/intersection-of-two-linked-lists/
topics: #linked_list #two_pointers
level: #easy
note: I've solved it with O(1) memory, that why it is becoming medium problem
LeetCode
Intersection of Two Linked Lists - LeetCode
Can you solve this real interview question? Intersection of Two Linked Lists - Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.…
💋7❤1🔥1
func minimumPushes(word string) int {
m := make([]int, 26)
for i := 0; i < len(word); i++ {
m[word[i]-97]++
}
result := 0
n := 0
for i, v := range m {
if m[i] == 0 { continue }
if n < 8 {
result += v
} else if n >= 8 && n < 16 {
result += (v*2)
} else if n >= 16 && n < 24 {
result += (v*3)
} else {
result += (v*4)
}
n++
}
return result
}https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i/?envType=daily-question&envId=2026-07-30
topics: #string #math
level: #easy
LeetCode
Minimum Number of Pushes to Type Word I - LeetCode
Can you solve this real interview question? Minimum Number of Pushes to Type Word I - You are given a string word containing distinct lowercase English letters.
Telephone keypads have keys mapped with distinct collections of lowercase English letters, which…
Telephone keypads have keys mapped with distinct collections of lowercase English letters, which…
❤4❤🔥3💘1
func smallestPalindrome(s string) string {
s = sortString(s)
m := map[byte]int{}
for i := 0; i < len(s); i++ {
m[s[i]]++
}
var oddChar byte
hasOdd := false
for k, v := range m {
if v % 2 != 0 {
oddChar = k
hasOdd = true
}
}
result := make([]byte, len(s))
if hasOdd {
result[len(s)/2] = oddChar
m[oddChar]--
}
j := len(s)-1
k := 0
i := 0
for i < len(s) {
if s[i] == oddChar && hasOdd {
i++
hasOdd = false
} else {
result[k], result[j] = s[i], s[i]
k++
j--
i+=2
}
}
return string(result)
}
func sortString(w string) string {
s := strings.Split(w, "")
sort.Strings(s)
return strings.Join(s, "")
}https://leetcode.com/problems/smallest-palindromic-rearrangement-i/?envType=daily-question&envId=2026-07-28
https://leetcode.com/problems/smallest-palindromic-rearrangement-i/?envType=daily-question&envId=2026-07-28
topics: #sorting #math
level: #medium
LeetCode
Smallest Palindromic Rearrangement I - LeetCode
Can you solve this real interview question? Smallest Palindromic Rearrangement I - You are given a palindromic string s.
Return the lexicographically smallest palindromic permutation of s.
Example 1:
Input: s = "z"
Output: "z"
Explanation:
A string…
Return the lexicographically smallest palindromic permutation of s.
Example 1:
Input: s = "z"
Output: "z"
Explanation:
A string…
❤3
public class Solution {
public int MaxArea(int[] height) {
var l = 0;
var r = height.Length-1;
var result = 0;
while (l < r) {
result = Math.Max(result, Math.Min(height[l], height[r])*(r-l));
if (height[l] < height[r]) l++;
else r--;
}
return result;
}
}https://leetcode.com/problems/container-with-most-water/ - One of the classic problems at leetcode. Best problem to understanding the two pointers pattern.
topics: #array #two_pointers
level: #medium
LeetCode
Container With Most Water - LeetCode
Can you solve this real interview question? Container With Most Water - You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).
Find two lines that together…
Find two lines that together…
❤2
func sortColors(nums []int) {
m := map[int]int{}
for _, n := range nums { m[n]++ }
currColor := 0
for i := 0; i < len(nums); i++ {
for m[currColor] == 0 {
currColor++
}
nums[i] = currColor
m[currColor]--
}
}https://leetcode.com/problems/sort-colors/
TC: O(n)
SC: O(1) - map at most has 3 values
topics: #array #sorting
level: #medium
approach: The pretty straight forward solution used counting sort
LeetCode
Sort Colors - LeetCode
Can you solve this real interview question? Sort Colors - You are given an array nums with n objects colored red, white, or blue, sort them in-place [https://en.wikipedia.org/wiki/In-place_algorithm] so that objects of the same color are adjacent, with the…
❤1🔥1
solving leetcode for fun
Photo
func shortestSubarray(nums []int, k int) int {
result := math.MaxInt
prefix := make([]int, len(nums)+1)
prefix[0] = 0
for i := 1; i < len(prefix); i++ {
prefix[i] = prefix[i-1]+nums[i-1]
}
maxdeq := []int{}
for r := 0; r < len(prefix); r++ {
for len(maxdeq) > 0 && prefix[r] < prefix[maxdeq[len(maxdeq) - 1]] {
maxdeq = maxdeq[:len(maxdeq) - 1]
}
maxdeq = append(maxdeq, r)
for len(maxdeq) > 0 && prefix[r] - prefix[maxdeq[0]] >= k {
result = min(result, r-maxdeq[0])
maxdeq = maxdeq[1:]
}
}
if result == math.MaxInt { return -1 }
return result
}https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/
P.S. Obviously that I couldn't solve this problem. But I figured out to use sliding window technique+prefix sum. I've got remaining part of solution(max deque) from solutions.
LeetCode
Shortest Subarray with Sum at Least K - LeetCode
Can you solve this real interview question? Shortest Subarray with Sum at Least K - Given an integer array nums and an integer k, return the length of the shortest non-empty subarray of nums with a sum of at least k. If there is no such subarray, return …
👍2🔥2💋2
func minimumTime(n int, relations [][]int, time []int) int {
graph := map[int][][2]int{}
for _, rel := range relations {
graph[rel[0]] = append(graph[rel[0]], [2]int{rel[1], time[rel[1]-1]})
}
memo := make([]int, n+1)
var fn func(node int) int
fn = func(node int) int {
if memo[node] != 0 {
return memo[node]
}
maxi := 0
for _, ngb := range graph[node] {
if memo[ngb[0]] != 0 {
maxi = max(memo[ngb[0]], maxi )
}
maxi = max(fn(ngb[0]), maxi)
}
memo[node] = time[node-1]+maxi
return memo[node]
}
result := 0
for i := 1; i <= n; i++ {
result = max(result, fn(i))
}
return result
}https://leetcode.com/problems/parallel-courses-iii/
topics: #graph #memoization #dfs
level: #hard
LeetCode
Parallel Courses III - LeetCode
Can you solve this real interview question? Parallel Courses III - You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCoursej, nextCoursej] denotes…
🔥3❤1👍1