π¬π§ 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.
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.
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
π¬π§Arrays. Practice.
Hello, folks! Let's solve problems today!
π’ Easy: 1480. Running Sum of 1d Array
π¨βπ» My solution: Java 3 Lines | 100% Faster solution
π‘ Medium one: 1828. Queries on Number of Points Inside a Circle
π¨βπ» My solution: Java Average Solution
Peace!
Hello, folks! Let's solve problems today!
π’ Easy: 1480. Running Sum of 1d Array
π¨βπ» My solution: Java 3 Lines | 100% Faster solution
π‘ Medium one: 1828. Queries on Number of Points Inside a Circle
π¨βπ» My solution: Java Average Solution
Peace!
LeetCode
Running Sum of 1d Array - LeetCode
Can you solve this real interview question? Running Sum of 1d Array - Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]β¦nums[i]).
Return the running sum of nums.
Example 1:
Input: nums = [1,2,3,4]
Output: [1,3β¦
Return the running sum of nums.
Example 1:
Input: nums = [1,2,3,4]
Output: [1,3β¦
π€©3
πΊπΏMassivlar. Amaliyot.
Hammaga salom! Keling, bugun masalalar yechaylik!
π’ Oson: 1480. Running Sum of 1d Array
π¨βπ» Mening yechimim: Java 3 Lines | 100% Faster solution
π‘ O'rta: 1828. Queries on Number of Points Inside a Circle
π¨βπ» Mening yechimim: Java Average Solution
Peace!
Hammaga salom! Keling, bugun masalalar yechaylik!
π’ Oson: 1480. Running Sum of 1d Array
π¨βπ» Mening yechimim: Java 3 Lines | 100% Faster solution
π‘ O'rta: 1828. Queries on Number of Points Inside a Circle
π¨βπ» Mening yechimim: Java Average Solution
Peace!
LeetCode
Running Sum of 1d Array - LeetCode
Can you solve this real interview question? Running Sum of 1d Array - Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]β¦nums[i]).
Return the running sum of nums.
Example 1:
Input: nums = [1,2,3,4]
Output: [1,3β¦
Return the running sum of nums.
Example 1:
Input: nums = [1,2,3,4]
Output: [1,3β¦
π7
π¬π§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!
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!
LeetCode
Calculate Money in Leetcode Bank - LeetCode
Can you solve this real interview question? Calculate Money in Leetcode Bank - Hercy wants to save money for his first car. He puts money in the Leetcode bank every day.
He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sundayβ¦
He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sundayβ¦
π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!
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!
LeetCode
Calculate Money in Leetcode Bank - LeetCode
Can you solve this real interview question? Calculate Money in Leetcode Bank - Hercy wants to save money for his first car. He puts money in the Leetcode bank every day.
He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sundayβ¦
He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sundayβ¦
π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.π€π€
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.π€π€
LeetCode
Power of Two - LeetCode
Can you solve this real interview question? Power of Two - Given an integer n, return true if it is a power of two. Otherwise, return false.
An integer n is a power of two, if there exists an integer x such that n == 2x.
Example 1:
Input: n = 1
Output:β¦
An integer n is a power of two, if there exists an integer x such that n == 2x.
Example 1:
Input: n = 1
Output:β¦
π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.π€π€
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.π€π€
LeetCode
Power of Two - LeetCode
Can you solve this real interview question? Power of Two - Given an integer n, return true if it is a power of two. Otherwise, return false.
An integer n is a power of two, if there exists an integer x such that n == 2x.
Example 1:
Input: n = 1
Output:β¦
An integer n is a power of two, if there exists an integer x such that n == 2x.
Example 1:
Input: n = 1
Output:β¦
π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:
To add data:
Array:
To retrieve data:
Array:
I hope, it was useful.
Catch you in the next oneπ€
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π€
Telegram
LeetCodin
π¬π§Hashtable
Hi, guys! I think we covered Binary trees and Recursion well enough to be able to solve problems on LeetCode. Let's start another topic today - Hashtable. I chose this topic because it was the second most voted choice in the poll. I'll leaveβ¦
Hi, guys! I think we covered Binary trees and Recursion well enough to be able to solve problems on LeetCode. Let's start another topic today - Hashtable. I chose this topic because it was the second most voted choice in the poll. I'll leaveβ¦
π€©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:
Ma'lumot qo'shish:
Massiv:
Ma'lumot olish:
Array:
Foydali bo'ldi degan umidaman.
Keyingi postlarda ko'rishguncha π€
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 π€
Telegram
LeetCodin
π¬π§Hashtable
Hi, guys! I think we covered Binary trees and Recursion well enough to be able to solve problems on LeetCode. Let's start another topic today - Hashtable. I chose this topic because it was the second most voted choice in the poll. I'll leaveβ¦
Hi, guys! I think we covered Binary trees and Recursion well enough to be able to solve problems on LeetCode. Let's start another topic today - Hashtable. I chose this topic because it was the second most voted choice in the poll. I'll leaveβ¦
π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π€
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π€
LeetCode
Find Median from Data Stream - LeetCode
Can you solve this real interview question? Find Median from Data Stream - The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values.
* For exampleβ¦
* For exampleβ¦
π₯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π€
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π€
LeetCode
Find Median from Data Stream - LeetCode
Can you solve this real interview question? Find Median from Data Stream - The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values.
* For exampleβ¦
* For exampleβ¦
π₯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π
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 π
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! π₯
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! π₯
LeetCode
Number of Good Pairs - LeetCode
Can you solve this real interview question? Number of Good Pairs - Given an array of integers nums, return the number of good pairs.
A pair (i, j) is called good if nums[i] == nums[j] and i < j.
Example 1:
Input: nums = [1,2,3,1,1,3]
Output: 4
Explanation:β¦
A pair (i, j) is called good if nums[i] == nums[j] and i < j.
Example 1:
Input: nums = [1,2,3,1,1,3]
Output: 4
Explanation:β¦
π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!π₯
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!π₯
LeetCode
Number of Good Pairs - LeetCode
Can you solve this real interview question? Number of Good Pairs - Given an array of integers nums, return the number of good pairs.
A pair (i, j) is called good if nums[i] == nums[j] and i < j.
Example 1:
Input: nums = [1,2,3,1,1,3]
Output: 4
Explanation:β¦
A pair (i, j) is called good if nums[i] == nums[j] and i < j.
Example 1:
Input: nums = [1,2,3,1,1,3]
Output: 4
Explanation:β¦
π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! πππ
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! πππ
Telegram
LeetCodin
I just have solved one really difficult (but medium level) problem on LeetCode. Here is the link to the problem: https://leetcode.com/problems/3sum/description/
It took several days to write a solution which passes the time requirements for it. Since itβ¦
It took several days to write a solution which passes the time requirements for it. Since itβ¦
π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! πππ
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! πππ
Telegram
LeetCodin
I just have solved one really difficult (but medium level) problem on LeetCode. Here is the link to the problem: https://leetcode.com/problems/3sum/description/
It took several days to write a solution which passes the time requirements for it. Since itβ¦
It took several days to write a solution which passes the time requirements for it. Since itβ¦
π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!
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!
Telegram
LeetCodin
πΊπΏO'zbekchada pastdaβ¬οΈ
π¬π§
Today I would like to briefly discuss Depth First Search (DFS). Usually, I use this recursive approach to solve problems with trees. You should consider the repetitive case/action which you apply on each iteration/node. Also, don'tβ¦
π¬π§
Today I would like to briefly discuss Depth First Search (DFS). Usually, I use this recursive approach to solve problems with trees. You should consider the repetitive case/action which you apply on each iteration/node. Also, don'tβ¦
π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!
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!
Telegram
LeetCodin
πΊπΏO'zimizchasi
Hammaga salom.
Bugun Depth First Search (DFS) haqida qisqacha yozmoqchiman. Meningcha, bu LeetCode da juda ham ko'p ishlatiladigan yondashuv. Odatda bu rekursiv yondashuvni men tree (daraxt) lar bilan bog'liq misollarni yechish uchun ishlataman.β¦
Hammaga salom.
Bugun Depth First Search (DFS) haqida qisqacha yozmoqchiman. Meningcha, bu LeetCode da juda ham ko'p ishlatiladigan yondashuv. Odatda bu rekursiv yondashuvni men tree (daraxt) lar bilan bog'liq misollarni yechish uchun ishlataman.β¦
π2