LeetCodin
1.4K subscribers
160 photos
3 videos
2 files
303 links
LeetCode 1700+
πŸ‡ΊπŸ‡ΏπŸ‡ΊπŸ‡Έ
Motto: ПобСда Π»ΡŽΠ±ΠΈΡ‚ ΠΏΠΎΠ΄Π³ΠΎΡ‚ΠΎΠ²ΠΊΡƒ

- Getting ready for FAANG | FAANGga tayyorlanamiz
- Data Structures and Algorithms | Ma'lumotlar tuzilmalari va Algoritmlar
- SWE at Deloitte πŸ‡ΊπŸ‡Έ
- LeetCode: https://leetcode.com/tbekpro/
Download Telegram
πŸ‡¬πŸ‡§ Arrays. For beginners.

Hi, guys! Before diving into Hashtables I think we need to cover Arrays.

Definition according to JavaTPoint is:
"An array is a collection of similar type of elements which has contiguous memory location." (link).

Let me explain "contiguous memory location" from the definition. Imagine that memory is divided into cells - bits which contain one of two values 0 or 1. When you initiate a variable, let's say int, which is 32-bit variable, then 32 such cells are allocated for this variable. Let's assume this is a box of 32 cells (bits) for one int variable πŸ“¦.

So, when you initialize an array of integers (int) with size of 5, then 5 such boxes, that are located back-to-back to each other, are assigned to the variable. You can imagine them as following: [πŸ“¦πŸ“¦πŸ“¦πŸ“¦πŸ“¦]

It is fast and easy to manipulate the elements of the array: you can access any value by its index in O(1) time.
πŸ‘1πŸ€”1
πŸ‡ΊπŸ‡ΏMassivlar. Yangi boshlaganlar uchun

Hammaga salom! Hashtable data structure haqida yozishdan oldin massivlar mavzusini o'tish kerak deb o'ylayman.

Massivning javatpoint.com saytidagi ta'rifi:
"Massiv - bu bir turdagi va xotirada yonma-yon joylashgan elementlar to'plami."

Ta'rifdagi "xotirada yonma-yon joylashgan" ifodasini tushuntirib berishga harakat qilaman. Bu dasturchilikni o'rganayotgan obunachilarga foydali bo'ladi degan umiddaman.

Tasavvur qilingki, xotira kichkina bo'limlarga - bit-larga bo'lingan. Bit 0 yoki 1 qiymatlarida bo'ladi. Integer (int) o'zgaruvchini yaratganingizda, shunday 32 ketma-ket bo'lgan bo'limlar kichkina blokni tashkil qiladi. Keling, shu blokni quticha (box) πŸ“¦ deymiz.

Agar 5ta integer (int) elementlardan iborat massiv yaratsak, shunday qutidan πŸ“¦ 5tasi yonma-yon joylashgan holda bo'ladi. Biz bularni quyidagicha tasavvur qilsak bo'ladi:
[πŸ“¦πŸ“¦πŸ“¦πŸ“¦πŸ“¦].

Massiv elementlarini manipulyatsiya qilish tez va oson: O(1) vaqtida istalgan indeksdagi qiymatni olishimiz mumkin. Bu operatsiya juda ham tez bajariladi.
πŸ‘4πŸ€”2
πŸ‡¬πŸ‡§Practice.

Hi, guys! Another day - another challenge!
Let's have some practice today, too.

🟒 Easy: 1716. Calculate Money in Leetcode Bank
πŸ‘¨β€πŸ’» My solution: Java 100% Faster | 3 solutions

This problem can be solved in different ways:
- using loop for each value,
- using HashMap to save all values and returning them,
- and others. Check them in my solution aboveπŸ˜‰

So far, I was able to find O(N) solution. But I'm quite sure, that there is O(1) solution, i.e. mathematical formula. So, I need to find that in future😁

🟒 Easy: 202. Happy Number
πŸ‘¨β€πŸ’» My solution: Java Solution using Map
I
used HashMap to find a moment when algorithm runs into a loop.

Keep coding!
πŸ‘1πŸ”₯1
πŸ‡ΊπŸ‡ΏAmaliyot.

Hayrli kech! Another day - another challenge!
Keling bugun ham amaliy mashqlar bajaraylik

🟒 Oson: 1716. Calculate Money in Leetcode Bank
πŸ‘¨β€πŸ’» Mening yechimim: Java 100% Faster | 3 solutions

Bu masalani har xil usulda yechish mumkin:
- loop ishlatib,
- HashMap ishlatib 1000gacha bo'lgan hamma qiymatlarini saqlash
va boshqalar. Yechimimni ko'rsangiz - tushunasiz πŸ˜‰

Shu masalaga O(N) yechim topa oldim, ammo, o'ylaymanki, bunga O(1) yechim topsa ham bo'ladi, chunki qaytarilanadigan pattern bor. Hali bu masalaga qaytib, O(1) yechim topishga yana harakat qilib ko'raman😁.

🟒 Oson: 202. Happy Number
πŸ‘¨β€πŸ’» Mening yechimim: Java Solution using Map
Loop holatiga tushganligini topish uchun HashMap ishlatdim.

Kod yozishni to'xtatmaymiz!
πŸ‘2❀1
πŸ‡¬πŸ‡§Practice. Again.

Hi, guys! Today we will have interesting practice.
I wrote 7 solutions to one problem (some of them does not differ that much from each other) while I was thinking of the one which would be 100% faster. That was so funnyπŸ˜„

🟒 Easy: 231. Power of Two
πŸ‘¨β€πŸ’» My solution: Java 7 solutions [Oh my Gosh!]

Please, share in the comments below if you find a different solution.πŸ€œπŸ€›
πŸ‘3
πŸ‡ΊπŸ‡ΏAmaliyot.

Hammaga salom! Bugun qiziqarli masala tayyorlab qo'ydim. Bu masala qiziq bo'lgani, unga 100% tez yechim topaman deb 7 har xil yechim topdim. Vaqtim qiziqarli o'tdiπŸ˜„

🟒 Oson: 231. Power of Two
πŸ‘¨β€πŸ’» Mening yechimim: Java 7 solutions [Oh my Gosh!]

Agar yanada yangi yechim topgan bo'lsangiz, pastda comment-larda bo'lishing.πŸ€œπŸ€›
😁4πŸ‘2❀1
πŸ‡¬πŸ‡§Hashtable. How to use.

Hi, guys! Here I started talking about Hashtable data structure (DS). Let's learn more about this DS on the example of HashMap in Java.

To be simple HashMap is a key-> value storage. Let's assume that you want to use String variables as keys and Integer values as values. So, you have already initialized the map:

Map<String, Integer> map = new HashMap<>();

And then you can start adding keys associated with values:

map.put("one", 1);
map.put("two", 2);

And after that when you need, you can retrieve those values by their keys:

map.get("one");
map.get("two");

Let's compare it to array the way HashMap is used.
To add data:
Array: array[index] = value
HashMap: map.put(key, value)

To retrieve data:
Array: array[index]
HashMap: map.get(key)

If you are a beginner, you can assume that map is a flexible array in terms of keys, because you can choose any type as a key (Integer, Character, String, etc).

I hope, it was useful.
Catch you in the next oneπŸ€“
🀩4πŸ‘2
πŸ‡ΊπŸ‡ΏHashtable ishlatilishi.

Hammaga salom! Bu post endi boshlayotganlar uchun.
Bu yerda Hashtable ma'lumot tuzilmasi (MT) haqida yozib boshlagan edim. Java tilidagi HashMap misolida shu MT haqida ko'proq o'rganamiz.

Hashmap - bu kalit->qiymat munosabatida ma'lumotlarni saqlash tuzilmasi. Masalan, siz String-larni kalit sifatida va Integer-larni qiymat sifatida ishlatmoqchisiz:

- HashMap-ni yaratish:
Map<String, Integer> map = new HashMap<>();

- ma'lumotni qo'shish:
map.put("bir", 1);
map.put("ikki", 2);

- ma'lumot olish:
map.get("bir");
map.get("ikki");

Keling massivlarni va HashMap-ni ishlatilishlarini taqqoslangan holda, ularni ishlatilishi tushunib olamiz.
Ma'lumot qo'shish:
Massiv: array[index] = value
HashMap: map.put(key, value)

Ma'lumot olish:
Array: array[index]
HashMap: map.get(key)

Farqi shundaki, HashMap-da kalit sifatida int-dan tashqari boshqa ma'lumot turini (data type) ishlatishingiz mumkin. Masalan, String yoki Character.

Foydali bo'ldi degan umidaman.
Keyingi postlarda ko'rishguncha πŸ€“
πŸ‘7
πŸ‡¬πŸ‡§Practice. Attention: Hard level

Hi, folks! Yesterday I challenged myself with a strange problem. It's hard task, but it was pretty easy to solve. This fact got me astonished.

πŸ”΄ Hard: 295. Find Median from Data Stream

You need to find the median for a changing set of numbers. It's really interesting problem. Try to solve it.

πŸ‘¨β€πŸ’»My solution: Java Solution

Sending good weekend vibes out thereπŸ€“
πŸ”₯2
πŸ‡ΊπŸ‡ΏAmaliyot. Diqqat: Qiyin masala

Salom, hammaga! Kecha o'zimni qiyin darajali masala bilan sinab ko'ray dedim. Qizig'i, unga yechim topish juda ham oson bo'ldi. Bu fakt meni hayratda qoldirdi.
"Kusto hayratda!"πŸ˜‚

πŸ”΄ Qiyin: 295. Find Median from Data Stream

Bu vazifada siz o'zgarayotgan raqamlar to'plamining ichidan median topishingiz kerak. Median - bu raqamlarning qiymatlari o'rtasida joylashgan raqam [o'rta arifmetik qiymat bilan adashtirmang]. Yechim topishga harakat qiling.

πŸ‘¨β€πŸ’» Mening yechimim: Java Solution

Bu post yaxshi vayblar bilan zaryadlanganπŸ€“
πŸ”₯4πŸ‘2
πŸ‡¬πŸ‡§Hashtable. Hashing.

Hi, guys! This is the next post about Hashtable data structure which we study on the example of HashMap in Java.

HashMap uses hashing to hash the key. Why? Because this helps to achieve O(1) time on data retrieval (like in arrays).

Let's assume if you use a list to store your data. In order to find a value from the list you need to loop over each value and compare to the searched value. So, the worst case scenario of such searching is O(N), in case the searched element does not exist in the list .

You may ask: Okay. I got this, but how hashed key helps to retrieve in O(1) time? To be simple, the answer is that hashmap is based on array data structure. HashMap takes the hash [of the key], calculates index for the array, which is inside of the HashMap, and references the element(hash, key, and value are stored in this element) with this index.

More to come:
- What if hashes are equal?
- How to deal with these cases?

So, this is it for today πŸ˜ƒ
Hope, this was useful😊
πŸ‘1🀩1
πŸ‡ΊπŸ‡ΏHashtable. Xeshlash.

Hammaga salom! Bugun Hashtable haqida yozishni davom etaman. Eslatib o'tamanki, bu ma'lumotlar tuzilmasini Java tilidagi HashMap implementation-nida o'rganamiz.

Hashmap-da put() method-ini ishlatganingizda kalit xeshlanadi. Nimaga? Chunki bu ma'lumotni O(1) tezligida chiqarib olish imkoniyatini beradi.

Tassavur qiling, biz ma'lumotlarni saqlash uchun HashMap emas List-ni ishlatamiz. Agar biz qaysidir elementni topmoqchi bo'lsak, biz har bir elementni ko'rib chiqamiz. List-ning ichida N-ta element bo'lsa, biz hammasini ko'rib chiqishimiz mumkin. Shunday qilib, bu qidirish algoritmi O(N) tezligiga ega.

Ho'p. Siz bunday savol berishingiz mumkin: Bunisi tushunarli. Ammo qanday qilib kalitning xeshlangan qiymati menga ma'lumotni chiqarib olishni O(1) tezlikda bajarib berishi mumkin?
Oddiy qilib aytganda, HashMap-ning ichida massiv ishlatiladi. HashMap xeshlangan qiymatni olib, undan index hisoblaydi va shu indexdagi object-ga xeshni, kalitni va qiymatni yozib qo'yadi.

Keyingi postlarda:
- Agar xeshlangan qiymatlar teng bo'lsachi?
- Bunday hollarda nima qilish kerak?

Hozircha shuπŸ˜ƒ
Foydali bo'ldi degan umiddaman 😊
πŸ‘7⚑1🀩1
πŸ‡¬πŸ‡§Practice: Hashtable.

Hi, guys! Today is practice day. I'll leave 1 easy and 1 medium level problem which can be solved using Hashtable data structure. Enjoy!

🟒 Easy: 1512. Number of Good Pairs
πŸ‘¨β€πŸ’» My solution: Java 100% Faster Solution

🟑 Medium: 535. Encode and Decode TinyURL
πŸ‘¨β€πŸ’» My solution: Java Straightforward Solution | HashMap

Don't stop coding! πŸ”₯
πŸ‘3πŸ₯°1
πŸ‡ΊπŸ‡Ώ Amaliyot: Hashtable.

Hammaga salom! Bugun vazifalarni bajaramiz. Men bitta oson va bitta o'rta darajali masala tayyorlab qo'ydim. Bularni Hashtable ma'lumotlar tuzilmasini ishlatgan holda yechishingiz mumkin. Boshladik!

🟒 Oson: 1512. Number of Good Pairs
πŸ‘¨β€πŸ’» Mening yechimim: Java 100% Faster Solution

🟑 O'rta darajali: 535. Encode and Decode TinyURL
πŸ‘¨β€πŸ’» Mening yechimim: Java Straightforward Solution | HashMap

Kod yozishni to'xtatmaymiz!πŸ”₯
πŸ‘4πŸ”₯1
πŸ‡¬πŸ‡§ WOW! 1 month.

Hi, guys! Today it is exactly 1 month since I started this channel. I tried to write post every single day. Thank you for being together on algorithms and data structure studying path. πŸ˜ƒ

Let me provide some numbers and topics.

So far we:
βœ… Covered topics: Recursion, Binary Tree Traversals, Arrays, HashTable (in progress).
βœ… Covered a topic on building Habits.
βœ… Covered 4️⃣5️⃣+ problems and solutions for them.
βœ… Can see that the most popular post is 3Sum post with 1️⃣0️⃣0️⃣0️⃣+ views.
βœ… Have the number of followers is 6️⃣5️⃣0️⃣+

Thank you for your interest! This motivates to keep this going! πŸ™ŒπŸ™ŒπŸ™Œ
πŸŽ‰3πŸ‘2πŸ”₯2
πŸ‡ΊπŸ‡Ώ Kusto hayratda! 1 oy!

Hammaga salom! Bu kanalni boshlaganimga roppa-rosa bir oy bo'libdi. Har kuni post yozishga harakat qildim. Algoritmlar va ma'lumotlar tuzilmasini men bilan birga o'rganayotganingiz uchun rahmat! πŸ˜ƒ

Ozgina statistik raqamlar va o'tilgan mavzular haqida:

βœ… Mavzular: Rekursiya, Binar Daraxtlarni aylanib o'tish, Massivlar, HashTable (o'rganayabmiz).
βœ… Foydali ko'nikmalarni hosil qilish haqida bitta post yozildi.
βœ… 4️⃣5️⃣+ ta masalaga yechimlar yozdik.
βœ… Eng ko'p o'qilgan post bu 3Sum post bo'ldi. Uni 1️⃣0️⃣0️⃣0️⃣+ marta o'qishibdi.
βœ… Obunachilar son 6️⃣5️⃣0️⃣+ ga yetdi.

Obuna bo'lganingiz uchun rahmat! Bu menga davom ettirishimga katta motivatsiya beradi! πŸ™ŒπŸ™ŒπŸ™Œ
πŸ‘20πŸ”₯6😁2πŸŽ‰1
πŸ‡¬πŸ‡§ Practice: Binary Tree and Recursion Rehearsal.

Hi, guys! Let's solve two problems on Binary Trees today. We discussed them here.

🟒 Easy: 257. Binary Tree Paths
πŸ‘¨β€πŸ’» My solution: Java DFS solution in 6 ms

🟑 Medium: 538. Convert BST to Greater Tree
πŸ‘¨β€πŸ’» My solution: Java Recursive Solution

Have a code day!
πŸ‘1🀩1
πŸ‡ΊπŸ‡Ώ Amaliyot: Binar Daraxtlar va Rekursiya takrorlaymiz.

Hammaga salom! Keling, bugun Binar daraxtlarni takrorlaymiz. Ularni yechish usuli haqida shu yerda yozganman.

🟒 Oson: 257. Binary Tree Paths
πŸ‘¨β€πŸ’» Mening yechimim: Java DFS solution in 6 ms

🟑 O'rta darajali: 538. Convert BST to Greater Tree
πŸ‘¨β€πŸ’» Mening yechimim: Java Recursive Solution

Have a code day!
πŸ‘2