Skip to content

Instantly share code, notes, and snippets.

View unilecs's full-sized avatar

UniLecs unilecs

View GitHub Profile
@unilecs
unilecs / RemoveInterval.cs
Last active November 11, 2024 20:15
Задача: Удаляем интервал
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static IList<IList<int>> RemoveInterval(int[][] intervals, int[] toBeRemoved) {
var list = new List<IList<int>>();
for (int i = 0; i < intervals.Length; i++)
{
@unilecs
unilecs / ReverseParentheses.cs
Created October 14, 2024 05:33
Задача: Реверс подстрок между скобками
using System;
using System.Text;
using System.Collections.Generic;
public class Program
{
public static void Reverse(StringBuilder sb, int start, int end) {
while (start < end) {
char temp = sb[start];
sb[start] = sb[end];
@unilecs
unilecs / MaxDepth.cs
Created September 29, 2024 23:57
Задача: Максимальная глубина вложенности скобок
using System;
public class Program
{
public static int MaxDepth(string s) {
int depth = 0;
int curDepth = 0;
for (int i = 0; i < s.Length; i++)
{
@unilecs
unilecs / HotPotato.cs
Created September 2, 2024 18:05
Задача: Горячая картошка
using System;
public class Program
{
public static int HotPotato(int n, int time) {
int full = time / (n - 1);
int extra = time % (n - 1);
int direction = full % 2 == 0 ? 1 : -1;
return direction == 1 ? extra + 1 : n - extra;
@unilecs
unilecs / ShareCoins.cs
Last active July 5, 2024 02:31
Задача. Рассыпать монеты
using System;
public class TreeNode
{
public int val;
public TreeNode left;
public TreeNode right;
public TreeNode(int val)
{
this.val = val;
@unilecs
unilecs / EvaluateTree.cs
Last active May 27, 2024 06:48
Задача: Бинарное булево дерево
using System;
public class Program
{
public class TreeNode
{
public int val;
public TreeNode left;
public TreeNode right;
public TreeNode(int val, TreeNode left=null, TreeNode right=null)
@unilecs
unilecs / FindMaxDepth.cs
Created May 8, 2024 05:15
Задача: Глубина скобок
using System;
public class Program
{
public static int FindMaxDepth(string s) {
int depth = 0;
int curDepth = 0;
for (int i = 0; i < s.Length; i++)
{
if (s[i] == '(') {
@unilecs
unilecs / CountSubArrays.cs
Last active April 15, 2024 05:31
Задача: Количество подмассивов, в которых максимальный элемент встречается не менее K раз
using System;
using System.Linq;
public class Program
{
public static long CountSubArrays(int[] nums, int k) {
int len = nums.Length;
int max = nums.Max();
int start = 0;
long res = 0; int maxCountInWindow = 0;
@unilecs
unilecs / FindMinNumOfUniqueIntegers.cs
Created April 1, 2024 02:06
Задача: Наименьшее количество различных целых чисел после K удалений
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static int FindMinNumOfUniqueIntegers(int[] arr, int k) {
var map = new Dictionary<int, int>();
for (int i = 0; i < arr.Length; i++)
{
@unilecs
unilecs / FindMaxLengthBetweenEqualCharacters.cs
Last active March 17, 2024 01:57
Задача: наибольшая подстрока между двумя одинаковыми символами
using System;
using System.Collections.Generic;
public class Program
{
public static int FindMaxLengthBetweenEqualCharacters(string s) {
int maxLen = -1;
var map = new Dictionary<char, int>();
for (int i = 0; i < s.Length; i++)
{