Skip to content

Instantly share code, notes, and snippets.

View unilecs's full-sized avatar

UniLecs unilecs

View GitHub Profile
@unilecs
unilecs / maximumBags.py
Created March 17, 2025 01:52
Задача: Оптимальное заполнение мешков (Python)
def maximumBags(capacity, rocks, additionalRocks):
# Вычитаем текущее количество камней из ёмкости
capacity = [c - r for c, r in zip(capacity, rocks)]
# Сортируем по возрастанию оставшегося места
capacity.sort()
result = 0
for space in capacity:
if space > 0 and additionalRocks == 0:
@unilecs
unilecs / MaxBags.cs
Created March 17, 2025 01:49
Задача: Оптимальное заполнение мешков
using System;
public class Program
{
public static int MaxBags(int[] capacity, int[] rocks, int additionalRocks) {
for (int i = 0; i < capacity.Length; i++)
{
capacity[i] -= rocks[i];
}
@unilecs
unilecs / DefuseBomb.cs
Last active January 24, 2025 05:15
Задача: Разминировать бомбу
using System;
public class Program
{
public static int[] DefuseBomb(int[] arr, int k) {
int N = arr.Length;
var res = new int[N];
if (k == 0) {
return res;
}
@unilecs
unilecs / CompressedStr.cs
Created December 10, 2024 06:11
Задача: Компрессия строки
using System;
using System.Text;
public class Program
{
public static string CompressedStr(string str) {
var res = new StringBuilder();
int index = 0;
while (index < str.Length)
@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)