Skip to content

Instantly share code, notes, and snippets.

@wahidustoz
Last active June 29, 2025 05:01
Show Gist options
  • Select an option

  • Save wahidustoz/c0b2075baaef2025032e6c713a817228 to your computer and use it in GitHub Desktop.

Select an option

Save wahidustoz/c0b2075baaef2025032e6c713a817228 to your computer and use it in GitHub Desktop.
Stackup | Challenges

1. To‑Do Manager — Predicate bilan filtrlash

Konsol ilovasi yozing:

  1. Task nomli record yarating (Id, Title, IsDone).
  2. List<Task> saqlang.
  3. Foydalanuvchiga quyidagi menyu ko‘rsating: add / list / list-done / toggle / exit.
  4. add — sarlavha so‘rang, yangi Task qo‘shing.
  5. list — hamma vazifalarni ko‘rsating.
  6. list-donePredicate<Task> orqali faqat IsDone == true bo‘lganlarini filtr qiling.
  7. toggle — Id bo‘yicha IsDone qiymatini o‘zgartiring.

Talablar
• Filtrlash logikasini alohida static metodda Predicate<Task> parametr bilan yozing.
• Id autoincrement bo‘lsin.
• Har bir buyruqdan so‘ng foydalanuvchi menyuga qaytadi.

Misol

cmd> add
Title: Buy milk
Task added (Id: 1)
cmd> add
Title: Write lab report
Task added (Id: 2)
cmd> list
1. Buy milk [ ]
2. Write lab report [ ]
cmd> toggle
Enter Id: 1
Task 1 marked done.
cmd> list-done
1. Buy milk [X]
cmd> exit

2. Temperatur kuzatuvchi — event + Action<double>

Sensordan kelayotgan har bir temperatura qiymatini konsolga chiqaradigan, lekin 40 °C dan oshsa ogohlantirish beradigan dastur yozing.

  1. TemperatureSensor klassi
    event Action<double> TemperatureMeasured;
    void Measure(double value) metodi eventni chaqirsin.

  2. TemperatureMonitor klassi
    • Konstruktorida sensorga subscribe qiladi.
    • Delegat: har qiymatni chiqaradi; agar value > 40, High temperature! deb yozadi.

  3. Program
    • Sensor yaratadi, monitor ulaydi.
    while ichida foydalanuvchidan qiymat olib, sensor.Measure() chaqiradi.

Qoida: Eventni ?.Invoke bilan chaqiring; subscription / unsubscription ni to‘g‘ri bajaring.

Misol

Input temp (or x): 36.5
Temp: 36.5°C
Input temp (or x): 42
Temp: 42°C  --> High temperature!
Input temp (or x): x
Exiting...

3. Matnni ketma‑ket o‘zgartirish — Func<string,string> pipeline

  1. List<Func<string,string>> konveyer yarating.

  2. Menyu buyruqlari:

    • upper – matnni katta harflarga o‘tkazish funksiyasini qo‘shish
    • trim – bo‘sh joylarni olib tashlaydigan funksiyani qo‘shish
    • reverse– matnni teskari qiluvchi funksiyani qo‘shish
    • run – foydalanuvchidan satr olib, pipeline bo‘yicha ishlatish
    • exit
  3. Agar pipeline bo‘sh bo‘lsa, run satrni o‘zgartirmaydi.

Misol

cmd> upper
Added UPPER.
cmd> reverse
Added REVERSE.
cmd> run
Enter text: hello
Result: OLLEH
cmd> exit

4. Chegirma strategiyasi — Func<decimal,decimal>

Internet‑do‘kon uchun narx hisoblash dasturi yozing.

  • Dictionary<string, Func<decimal, decimal>> strategies yarating:
    • none → narxni o‘zgartirmaydi
    • vip → 20 % chegirma
    • blackfriday → 50 % chegirma
  • Foydalanuvchidan narx va strategiya nomi so‘raladi.
  • Belgilanmagan nom uchun none ishlatiladi.
  • Yakuniy narxni 2 kasr belgisi bilan formatlab chiqaring.

Misollar

Price: 200
Discount type (none/vip/blackfriday): vip
Final: 160.00
Price: 100
Discount type (none/vip/blackfriday): student
Final: 100.00

5. Bank hisob raqami — event EventHandler<decimal>

Bank hisobida balans o‘zgarishini kuzatib boruvchi dastur yozing.

  1. BankAccount klassi

    • public event EventHandler<decimal>? BalanceChanged;
    • Deposit(decimal amount) va Withdraw(decimal amount) balansni o‘zgartiradi; har ikkisi eventni chaqiradi.
    • Withdraw balans yetarli bo‘lmasa xabar chiqarib, event chaqirmasin.
  2. Program

    • Hisob yaratadi.
    • Eventga obuna bo‘lib, Balance: XX.XX formatida balansni chiqaradi.
    • Foydalanuvchidan d (deposit), w (withdraw) yoki x (exit) va summani oladi.

Eʼtibor: Eventni trigger qilayotganda ?.Invoke(this, balance) dan foydalaning.

Misol

Command (d/w/x): d
Amount: 150
Balance: 150
Command (d/w/x): w
Amount: 70
Balance: 80
Command (d/w/x): w
Amount: 100
Insufficient funds.
Command (d/w/x): x
Goodbye!

1. Convert Age

Write a C# function that converts given age in years into days.

  • consider a year has 365 days
  • ignore leap years
Example
Input Output
65 23725
0 0
20 7300
public int AgeInDays(int ageInYears)
{
    // your code here
}

2. Basketball Score

You are counting total score for a basketball game. In basketball, players can score 2 pointer shots and 3 pointer shots. Given the number of 2 pointers and 3 pointers, you need to calculate the total score.

Example
Input Output
1 1 5
7 5 29
38 8 100
public int CalculateTotalScore(int twoPointers, int threePointers)
{
    // your code here
}

3. Formal Name

Given the first name, last name and a boolean representing if a person is a male, write a C# function which returns the formal name in {Mr.|Mrs.} {First name} {Last name} format.

  • First name and last name should always be Title Case
Example
Input Output
"john" "DOE" true Mr. John Doe
"wahid" "AbDuHaKimOv" true Mr. Wahid Abduhakimov
hermione Granger false Mrs. Hermoine Granger
public string FormalName(string firstName, string lastName, bool isMale)
{
    // your code here
}

📘 Problem Submission Instructions

Follow the steps below to submit your solutions correctly. This will help ensure your work is reviewed and organized properly. ✅


🛠️ How to Submit Your Solutions

Please submit your answers as comments on this Gist by following these instructions:

1️⃣ Solve the Problem Locally

  • Open the problems in your Visual Studio Code (or your preferred C# editor).
  • Solve the problem(s) in a .cs file.
  • Save your solution when you’re done.

2️⃣ Take a Snapshot 📸

  • In VS Code, take a screenshot (snapshot) of your solution code window showing:
    • The solution code
    • Problem number and name as a comment (optional but helpful)
  • Make sure the code is readable in the snapshot.

3️⃣ Post a Comment 💬

For each solution, do the following:

  • Add a new comment to this Gist.
  • In the comment, include:
    • ✏️ Problem Number (e.g., Problem 3)
    • 🖼️ Your screenshot of the solution as an attachment
    • 💡 Optionally, include any notes or explanation

Example Comment:

1. Checked addition

Write a C# function to add two integers and return the result. Return -1 if the addition overflows.

Example
Input Output
1 2 3
2147483647 2147483647 -1
public int CheckedAdd(int a, int b)
{
    // your code here
}

2. Clean number

Write a C# function which accepts a string with numbers, spaces and special characters in it. Clean out the all non-numeric characters and parse the string into single BigInteger type.

If the string doesnt contain numeric characters, then return a BigInteger with value 0.

Example
Input Output
1 2 12
21##47 48asdf3647 2147483647
asdf<>?< 0
public BigInteger CleanNumber(string str)
{
    // your code here
}

3. Add Transactions

You are building a financial transaction tracking system for a large corporation. Due to the scale of operations, transactions involve extremely large amounts of money represented as strings. Implement a function AddTransaction that takes two transaction amounts represented as strings and returns their sum.

Example
Input Output
"" "" 0
"1231231231231231233123123123123123123123" "1231231231231231233123123123123123123123" 2462462462462462466246246246246246246246
public BigInteger AddTransactions(string amount1, string amount2)
{
    // your code here
}

4. Predict Population

In a demographic study, you're analyzing population growth over several decades. Implement a function PredictPopulation that takes the initial population size and growth rate and predicts the population after a certain number of years.

Example
Input Output
500000 3 10 48828125000000000000
1000 1 20 1000
public BigInteger PredictPopulation(BigInteger initialPopulation, int growthRate, int years) 
{
    // Your code here
}

5. Currency Conversion

You are building a currency conversion tool that needs to accurately convert an amount from one currency to another. Implement a function ConvertCurrency that takes a decimal amount in one currency and a float exchange rate, and returns the equivalent amount in the target currency.

Example
Input Output
1000 12663.90 12663900
public decimal ConvertCurrency(decimal amount, float rate) 
{
    // Your code here
}

1. Reverse String

Write a C# function to reverse a given string without using any built-in string reversal functions.

Example
Input Output
hello olleh
world dlrow
public string Reverse(string str)
{
    // your code here
}

2. Is it anagram?

Implement a function to check if two strings are anagrams of each other.

Example
Input Output
silent listen true
hello world false
public bool AreAnagrams(string str1, string str2)
{
    // your code here
}

3. Longest Palindrome

Write a program to find the longest palindrome substring within a given string.

Example
Input Output
forgeeksskeegfor geeksskeeg
abracadabra aca
aba aba
public string LongestPalindromeWithin(string str)
{
    // your code here
}

4. Remove Duplicates

Implement a function to remove duplicate characters from a string without using any additional data structures.

Example
Input Output
hello helo
world world
abracadabra cd
public string RemoveDuplicates(string str)
{
    // your code here
}

5. Valid Palindrome

Create a method to check if a given string is a valid palindrome, considering only alphanumeric characters and ignoring cases.

Example
Input Output
race car true
race a car false
A man, a plan, a canal: Panama true
public bool IsValidPalindrome(string str)
{
    // your code here
}

6. First non-repeated character

Write a program to find the first non-repeated character in a given string.

Example
Input Output
hello h
abracadabra c
public char FirstNonRepeatedCharacter(string str)
{
    // your code here
}

7.

Implement a function to perform string compression, where consecutive characters are replaced with the count of the character followed by the character itself.

Example
Input Output
aabcccccaaa a2b1c5a3
aabbcc a2b2c2
public string Compress(string str)
{
    // your code here
}

@AbduvaliMamatov
Copy link

3.2
image

@AbduvaliMamatov
Copy link

3.3
image
image

@AbduvaliMamatov
Copy link

3.4
image

@AbduvaliMamatov
Copy link

3.5
image

@AbduvaliMamatov
Copy link

3.6
image

@AbduvaliMamatov
Copy link

3.7
image

@AZIZPRIME01
Copy link

task3

@AZIZPRIME01
Copy link

task7
task8
task9
taskfour
taskone
taskten
tasktwo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment