πΊπΏ Amaliyot.
Hammaga salom! Bugun masala yechamiz. Shu masalaga men yozgan yechimni beraman va keyingi postda izohini berishga harakat qilaman.
π‘ O'rta daraja: 75. Sort Colors
π¨βπ» Mening yechimim:
Java 100% Faster | O(N + N) Solution
O'zingiz yechishga harakat qiling.
Omad!βοΈ
Hammaga salom! Bugun masala yechamiz. Shu masalaga men yozgan yechimni beraman va keyingi postda izohini berishga harakat qilaman.
π‘ O'rta daraja: 75. Sort Colors
π¨βπ» Mening yechimim:
Java 100% Faster | O(N + N) Solution
O'zingiz yechishga harakat qiling.
Omad!βοΈ
LeetCode
Sort Colors - LeetCode
Can you solve this real interview question? Sort Colors - You are given an array nums with n objects colored red, white, or blue, sort them in-place [https://en.wikipedia.org/wiki/In-place_algorithm] so that objects of the same color are adjacent, with theβ¦
π5
π¬π§ Problem 75. Sort Colors Explained
π‘ Medium: 75. Sort Colors
π¨βπ» My solution:
Java 100% Faster | O(N + N) Solution
Hi, guys! It's time to show solution for yesterday's task and explain it. Let's gooo!
π¨βπ» Task.
Basically, you are given array which has only values 0, 1, 2 and not ordered. Your task is to sort the array without using any library sorting algo.
Pay attention to that we don't return any array and we need to provide result inside given array.
π¨βπ» My solution:
- I run thru array two times.
- In the first run, I count the number of 0's and 1's and store them in n0 and n1 respectively.
- In the second run, I insert 0's from the beginning until we run out of 0's. Then I insert 1's into array until we run out of 1's. Then I just fill the array with 2's till the end.
That's it.
Hope you enjoyed it! πβοΈ
π‘ Medium: 75. Sort Colors
π¨βπ» My solution:
Java 100% Faster | O(N + N) Solution
Hi, guys! It's time to show solution for yesterday's task and explain it. Let's gooo!
π¨βπ» Task.
Basically, you are given array which has only values 0, 1, 2 and not ordered. Your task is to sort the array without using any library sorting algo.
Pay attention to that we don't return any array and we need to provide result inside given array.
π¨βπ» My solution:
class Solution {
public void sortColors(int[] nums) {
int n0 = 0, n1 = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] == 0) n0++;
else if (nums[i] == 1) n1++;
}
for (int i = 0; i < nums.length; i++) {
if (n0-- > 0) nums[i] = 0;
else if (n1-- > 0) nums[i] = 1;
else nums[i] = 2;
}
}
}
π¨βπ» Explanation.- I run thru array two times.
- In the first run, I count the number of 0's and 1's and store them in n0 and n1 respectively.
- In the second run, I insert 0's from the beginning until we run out of 0's. Then I insert 1's into array until we run out of 1's. Then I just fill the array with 2's till the end.
That's it.
Hope you enjoyed it! πβοΈ
LeetCode
Sort Colors - LeetCode
Can you solve this real interview question? Sort Colors - You are given an array nums with n objects colored red, white, or blue, sort them in-place [https://en.wikipedia.org/wiki/In-place_algorithm] so that objects of the same color are adjacent, with theβ¦
π1
πΊπΏ 75. Sort Colors Masalasi
π‘ O'rta daraja: 75. Sort Colors
π¨βπ» Mening yechimim:
Java 100% Faster | O(N + N) Solution
Hammaga salom! Kechagi masalaning yechimini ko'rsatib, uni tushuntirish vaqti keldi. Boshladik!πππ
π¨βπ» Vazifa.
Oddiy qilib aytganda, bizga 0,1 va 2 sonlari bilan tartibsiz holda to'ldirilgan massiv berilgan. Bizning vazifamiz bu massivni tartibga solish (sort).
Ahamiyat bering: natijani berilgan massivning o'ziga saqlashimiz lozim.
π¨βπ» Mening yechimim:
- Massivni ikki marta aylanib chiqaman.
- Birinchi marta aylanganda 0lar va 1lar sonini hisoblab, n0 va n1 o'zgaruvchilari orqali saqlayman.
- Ikkinchi marta aylanganda massivni boshida 0lar bilan to'ldiraman. 0lar tugaganda, 1lar bilan to'ldirib boshlayman. 1lar ham tugaganda - massivning qolgan qismini 2'lar bilan to'ldirib chiqaman.
Bo'ldi. Tugadi.
Sizlarga yoqdi degan umiddaman! πβοΈ
π‘ O'rta daraja: 75. Sort Colors
π¨βπ» Mening yechimim:
Java 100% Faster | O(N + N) Solution
Hammaga salom! Kechagi masalaning yechimini ko'rsatib, uni tushuntirish vaqti keldi. Boshladik!πππ
π¨βπ» Vazifa.
Oddiy qilib aytganda, bizga 0,1 va 2 sonlari bilan tartibsiz holda to'ldirilgan massiv berilgan. Bizning vazifamiz bu massivni tartibga solish (sort).
Ahamiyat bering: natijani berilgan massivning o'ziga saqlashimiz lozim.
π¨βπ» Mening yechimim:
class Solution {
public void sortColors(int[] nums) {
int n0 = 0, n1 = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] == 0) n0++;
else if (nums[i] == 1) n1++;
}
for (int i = 0; i < nums.length; i++) {
if (n0-- > 0) nums[i] = 0;
else if (n1-- > 0) nums[i] = 1;
else nums[i] = 2;
}
}
}
π¨βπ»Izoh- Massivni ikki marta aylanib chiqaman.
- Birinchi marta aylanganda 0lar va 1lar sonini hisoblab, n0 va n1 o'zgaruvchilari orqali saqlayman.
- Ikkinchi marta aylanganda massivni boshida 0lar bilan to'ldiraman. 0lar tugaganda, 1lar bilan to'ldirib boshlayman. 1lar ham tugaganda - massivning qolgan qismini 2'lar bilan to'ldirib chiqaman.
Bo'ldi. Tugadi.
Sizlarga yoqdi degan umiddaman! πβοΈ
LeetCode
Sort Colors - LeetCode
Can you solve this real interview question? Sort Colors - You are given an array nums with n objects colored red, white, or blue, sort them in-place [https://en.wikipedia.org/wiki/In-place_algorithm] so that objects of the same color are adjacent, with theβ¦
π7π1
π¬π§ Practice.
Hi, guys! Today's task is Tribonacci task. It's like Fibonacci, but Tribonacci.π
π’ Easy: 1137. N-th Tribonacci Number
π¨βπ» My solution: Java 100% Faster | Array As A Cache
Try to write the fastest solution. And we'll analyze the solution in the next post.
Peace!βοΈ
Hi, guys! Today's task is Tribonacci task. It's like Fibonacci, but Tribonacci.π
π’ Easy: 1137. N-th Tribonacci Number
π¨βπ» My solution: Java 100% Faster | Array As A Cache
Try to write the fastest solution. And we'll analyze the solution in the next post.
Peace!βοΈ
LeetCode
N-th Tribonacci Number - LeetCode
Can you solve this real interview question? N-th Tribonacci Number - The Tribonacci sequence Tn is defined as follows:
T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
Given n, return the value of Tn.
Example 1:
Input: n = 4
Output:β¦
T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
Given n, return the value of Tn.
Example 1:
Input: n = 4
Output:β¦
π4
πΊπΏ Amaliyot.
Hammaga salom! Bugun oson darajali masala yechamiz - Tribonachi ketma-ketligi. U xuddi Fibonachi kabi, lekin Tribonachidir.π
π’ Oson daraja: 1137. N-th Tribonacci Number
π¨βπ» Mening yechimim: Java 100% Faster | Array As A Cache
Eng tez yechim yozishga harakat qiling.
Keyingi postda sizlar bilan yechimni tahlil qilib chiqamiz.
Peace!βοΈ
Hammaga salom! Bugun oson darajali masala yechamiz - Tribonachi ketma-ketligi. U xuddi Fibonachi kabi, lekin Tribonachidir.π
π’ Oson daraja: 1137. N-th Tribonacci Number
π¨βπ» Mening yechimim: Java 100% Faster | Array As A Cache
Eng tez yechim yozishga harakat qiling.
Keyingi postda sizlar bilan yechimni tahlil qilib chiqamiz.
Peace!βοΈ
LeetCode
N-th Tribonacci Number - LeetCode
Can you solve this real interview question? N-th Tribonacci Number - The Tribonacci sequence Tn is defined as follows:
T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
Given n, return the value of Tn.
Example 1:
Input: n = 4
Output:β¦
T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
Given n, return the value of Tn.
Example 1:
Input: n = 4
Output:β¦
π9π1
π¬π§ Practice.
Hi, guys! Let me explain my solution for yesterday's problem.
π’ Easy: 1137. N-th Tribonacci Number
π¨βπ» My solution: Java 100% Faster | Array As A Cache
π¨βπ» Task.
The task is to find the n-th element in tribonacci sequence. It's the same as Fibonacci, but here the element is the sum of previous three element. More on Fibonacci sequence you can read here.
π¨βπ» My solution:
Solution is below in the picture.
π¨βπ» Explanation.
1. My solution is based on recursive approach with memoization. I wrote a post on this here. So, what I do is first cover 3 base cases: for n = 0, n = 1, n = 2.
2. As you can see I used an array of size 38 as a cache. We need a cache to store the result for cases which we have already gone through. This is done for optimization purposes.
Q: Why the size of the cache array is 38?
A: Because in the task description n is between 1 and 37. The size is 38 because I want to store value by its index, not index - 1.
Q: Why you use array instead of Hashtable data structure implementation?
A: Simply saying, I don't need it πππ. HashMap, Hashtable implementation in Java, needs some more memory and, even if its access speed to element is O(1) [if no collision], has some extra operations for hashing, inserting, and retrieving elements. It takes time. Array requires less resources. Choose Arrays!
Just choose it!π
3.
4. else case is the recursive expression. Mathematically we can write: f(x) = f(x-1) + f(x - 2) + f(x - 3).
This is it. I hope you liked the solution.
Peace!βοΈ
Hi, guys! Let me explain my solution for yesterday's problem.
π’ Easy: 1137. N-th Tribonacci Number
π¨βπ» My solution: Java 100% Faster | Array As A Cache
π¨βπ» Task.
The task is to find the n-th element in tribonacci sequence. It's the same as Fibonacci, but here the element is the sum of previous three element. More on Fibonacci sequence you can read here.
π¨βπ» My solution:
Solution is below in the picture.
π¨βπ» Explanation.
1. My solution is based on recursive approach with memoization. I wrote a post on this here. So, what I do is first cover 3 base cases: for n = 0, n = 1, n = 2.
2. As you can see I used an array of size 38 as a cache. We need a cache to store the result for cases which we have already gone through. This is done for optimization purposes.
Q: Why the size of the cache array is 38?
A: Because in the task description n is between 1 and 37. The size is 38 because I want to store value by its index, not index - 1.
Q: Why you use array instead of Hashtable data structure implementation?
A: Simply saying, I don't need it πππ. HashMap, Hashtable implementation in Java, needs some more memory and, even if its access speed to element is O(1) [if no collision], has some extra operations for hashing, inserting, and retrieving elements. It takes time. Array requires less resources. Choose Arrays!
Just choose it!π
3.
if (cache[n] > 0) return cache[n]; - let's see what is going on here. Note that the array is an array with primitive types. When such array is created, all values will be equal to the default value of that type. In our case, the primitive type is integer and the default for it is 0. So, this if expression means that if value for index n is added, then return its value (we have already gone through this case).4. else case is the recursive expression. Mathematically we can write: f(x) = f(x-1) + f(x - 2) + f(x - 3).
This is it. I hope you liked the solution.
Peace!βοΈ
LeetCode
N-th Tribonacci Number - LeetCode
Can you solve this real interview question? N-th Tribonacci Number - The Tribonacci sequence Tn is defined as follows:
T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
Given n, return the value of Tn.
Example 1:
Input: n = 4
Output:β¦
T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
Given n, return the value of Tn.
Example 1:
Input: n = 4
Output:β¦
π3π€©1
πΊπΏ Amaliyot.
Hammaga salom! Keling bugun kechagi masalaning yechimini tahlil qilaylik.
π’ Oson daraja: 1137. N-th Tribonacci Number
π¨βπ» Mening yechimim: Java 100% Faster | Array As A Cache
π¨βπ» Vazifa.
Bizning vazifamiz bu Tribonacci ketma-ketligidagi n-elementini topish. U xuddi Fibonachi sonlar ketma-ketligiga o'xshaydi, lekin farqi bu har bir element undan oldin turgan uchta elementning yig'indisiga tengdir. Fibonachi sonlare haqida bu yerda o'qisangiz bo'ladi.
π¨βπ» Mening yechimim:
Yechimni rasm orqali ko'rsatganman.
π¨βπ»Izoh
1. Mening yechimim memoizatsiyani ishlatuvchi rekursiv usulga asoslangan. Bu usul haqida yozganman: havola. Shunday qilib, asosiy holatlardan boshlaymiz. Bular: n = 0, n = 1, n = 2 holatlari.
2. Men hajmi 38 elementlik massivni kesh sifatida ishlatdim. Keshni ishlatishimiz sababi - bu bir marta hisoblangan qiymatlarni saqlab qolib, qayta ularni hisoblashga vaqt ketkazmaslik. Bu orqali optimizatsiyaga erishamiz.
S: Nimaga massivning hajmi 38ga teng?
J: Vazifani o'qisak, berilayotgan n soni 1 va 37 orasida bo'ladi. Hajmini esa 38ga teng qildim, chunki qiymatlarni n ga teng bo'lgan indekslar orqali saqlamoqchiman, indeks - 1 bo'yicha emas.
S: Nimaga massiv ishlatilgan? Hashtable ma'lumotlar tuzilmasini ishlatsa bo'ladiku.
J: Oddiy qilib aytadigan bo'lsam, menga u kerak emas edi ham (ishlatgim ham kelmadi, ochig'i).πππ Java-da Hashtable-ning implementatsiyalaridan biri HashMap ko'proq xotira va, xeshlash, kiritish va olish operatsiyalariga, vaqt talab qiladi. HashMap-ning elementni olish tezligi O(1) deyilsa ham [kolliziya bo'lmagan holda], bu O(1) konstanta massivning o'xshash operatsiyalaridagi O(1) dan kattaroq.
Massivni tanlang! Massivga ovoz bering!π
3.
4. else-da esa rekursiyaviy ifodamiz. Uni matematik holda yozadigan bo'lsak, f(x) = f(x-1) + f(x - 2) + f(x - 3) - ko'rinishda bo'ladi. Bu ko'rinishda tushunish osonroq :).
Sizga yoqdi degan umiddaman.
Omad!βοΈ
Hammaga salom! Keling bugun kechagi masalaning yechimini tahlil qilaylik.
π’ Oson daraja: 1137. N-th Tribonacci Number
π¨βπ» Mening yechimim: Java 100% Faster | Array As A Cache
π¨βπ» Vazifa.
Bizning vazifamiz bu Tribonacci ketma-ketligidagi n-elementini topish. U xuddi Fibonachi sonlar ketma-ketligiga o'xshaydi, lekin farqi bu har bir element undan oldin turgan uchta elementning yig'indisiga tengdir. Fibonachi sonlare haqida bu yerda o'qisangiz bo'ladi.
π¨βπ» Mening yechimim:
Yechimni rasm orqali ko'rsatganman.
π¨βπ»Izoh
1. Mening yechimim memoizatsiyani ishlatuvchi rekursiv usulga asoslangan. Bu usul haqida yozganman: havola. Shunday qilib, asosiy holatlardan boshlaymiz. Bular: n = 0, n = 1, n = 2 holatlari.
2. Men hajmi 38 elementlik massivni kesh sifatida ishlatdim. Keshni ishlatishimiz sababi - bu bir marta hisoblangan qiymatlarni saqlab qolib, qayta ularni hisoblashga vaqt ketkazmaslik. Bu orqali optimizatsiyaga erishamiz.
S: Nimaga massivning hajmi 38ga teng?
J: Vazifani o'qisak, berilayotgan n soni 1 va 37 orasida bo'ladi. Hajmini esa 38ga teng qildim, chunki qiymatlarni n ga teng bo'lgan indekslar orqali saqlamoqchiman, indeks - 1 bo'yicha emas.
S: Nimaga massiv ishlatilgan? Hashtable ma'lumotlar tuzilmasini ishlatsa bo'ladiku.
J: Oddiy qilib aytadigan bo'lsam, menga u kerak emas edi ham (ishlatgim ham kelmadi, ochig'i).πππ Java-da Hashtable-ning implementatsiyalaridan biri HashMap ko'proq xotira va, xeshlash, kiritish va olish operatsiyalariga, vaqt talab qiladi. HashMap-ning elementni olish tezligi O(1) deyilsa ham [kolliziya bo'lmagan holda], bu O(1) konstanta massivning o'xshash operatsiyalaridagi O(1) dan kattaroq.
Massivni tanlang! Massivga ovoz bering!π
3.
if (cache[n] > 0) return cache[n]; - bu yerda nima bo'layotganini ko'raylik. Ahamiyat bering, men ishlatgan massiv - bu primitiv ma'lumot turidagi elementlardan iborat massiv. Qachonki shunday massiv yaratsak, u ishlatilgan primitiv turining default [tarjimasini topsangiz - yozib yuboring] qiymati bilan to'ldiriladi. Bizning holda bu 0. Shunday qilib, if -ning ma'nosi: agar n uchun qiymat topgan bo'lsak, shu qiymatni ishlataman, agar topmagan bo'lsak - qidiramiz.4. else-da esa rekursiyaviy ifodamiz. Uni matematik holda yozadigan bo'lsak, f(x) = f(x-1) + f(x - 2) + f(x - 3) - ko'rinishda bo'ladi. Bu ko'rinishda tushunish osonroq :).
Sizga yoqdi degan umiddaman.
Omad!βοΈ
LeetCode
N-th Tribonacci Number - LeetCode
Can you solve this real interview question? N-th Tribonacci Number - The Tribonacci sequence Tn is defined as follows:
T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
Given n, return the value of Tn.
Example 1:
Input: n = 4
Output:β¦
T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.
Given n, return the value of Tn.
Example 1:
Input: n = 4
Output:β¦
π4π»1
π¬π§ Practice [makes it better]
Hi, guys! Let's solve one interesting medium problem today. Shortly, you will work with interesting palindromes.
π‘ Medium: 2396. Strictly Palindromic Number
π¨βπ» My solution: Java 0ms 100% faster solution
As usual, solution will be explained in the next post. π
Peace! βοΈ
Hi, guys! Let's solve one interesting medium problem today. Shortly, you will work with interesting palindromes.
π‘ Medium: 2396. Strictly Palindromic Number
π¨βπ» My solution: Java 0ms 100% faster solution
As usual, solution will be explained in the next post. π
Peace! βοΈ
LeetCode
Strictly Palindromic Number - LeetCode
Can you solve this real interview question? Strictly Palindromic Number - An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.
Given an integer n,β¦
Given an integer n,β¦
π5
πΊπΏ Amaliyot [makes is better]
Hammaga salom! Keling bitta juda ham qiziqarli bo'lgan masalani yechamiz. Qisqa qilib aytganda, sizlar bir sonning har xil palindromlari bilan ishlaysiz.
π‘ O'rta daraja: 2396. Strictly Palindromic Number
π¨βπ» Mening yechimim: Java 0ms 100% faster solution
Har doimgidek yechimini ertaga izohlab berishga harakat qilaman. πππ
Omad! βοΈ
Hammaga salom! Keling bitta juda ham qiziqarli bo'lgan masalani yechamiz. Qisqa qilib aytganda, sizlar bir sonning har xil palindromlari bilan ishlaysiz.
π‘ O'rta daraja: 2396. Strictly Palindromic Number
π¨βπ» Mening yechimim: Java 0ms 100% faster solution
Har doimgidek yechimini ertaga izohlab berishga harakat qilaman. πππ
Omad! βοΈ
LeetCode
Strictly Palindromic Number - LeetCode
Can you solve this real interview question? Strictly Palindromic Number - An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.
Given an integer n,β¦
Given an integer n,β¦
π8π»4
Bugun zoβr dasturchilar bilan tanishdim.
Today I was happy to get to know these great programmers.
Oldik!π₯
Today I was happy to get to know these great programmers.
Oldik!π₯
π¨βπ»33π6π6π€©5πΎ2π€‘1
π¬π§ 2396. Strictly Palindromic Number
Hi, guys! Today I wanted to explain my solution, but realized that there is 1 line solution for the problem. So, let's analyze it.
π‘ Medium: 2396. Strictly Palindromic Number
π¨βπ» Task:
We need to find all base representations from 2 to n - 2 for given n. And we need to return true if all of these representations are palindromic, else return false.
π¨βπ» Best solution:
Why does it always return false? Because base(n - 2) representation of any number (given by task) will be "12", which is not palindromic.
For example, let's take n = 21. Then base(n-2) will be base(19). Let's find base(19) representation for 21.
1. 21 / 19 is 1 with remainder 2. We write "2" and then "1". We get "21" and then revert it according to rules. Finally, we get "12".
I hope this made it clear!
Peace!βοΈ
Hi, guys! Today I wanted to explain my solution, but realized that there is 1 line solution for the problem. So, let's analyze it.
π‘ Medium: 2396. Strictly Palindromic Number
π¨βπ» Task:
We need to find all base representations from 2 to n - 2 for given n. And we need to return true if all of these representations are palindromic, else return false.
π¨βπ» Best solution:
public boolean isStrictlyPalindromic(int n) {
return false;
}
π¨βπ» Explanation:Why does it always return false? Because base(n - 2) representation of any number (given by task) will be "12", which is not palindromic.
For example, let's take n = 21. Then base(n-2) will be base(19). Let's find base(19) representation for 21.
1. 21 / 19 is 1 with remainder 2. We write "2" and then "1". We get "21" and then revert it according to rules. Finally, we get "12".
I hope this made it clear!
Peace!βοΈ
LeetCode
Strictly Palindromic Number - LeetCode
Can you solve this real interview question? Strictly Palindromic Number - An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.
Given an integer n,β¦
Given an integer n,β¦
π3π₯2β€βπ₯1
πΊπΏ 2396. Strictly Palindromic Number
Hammaga salom! Men o'zimning yechimimning izohini bermoqchi edim, ammo menikidan ancha yaxshiroq yechim borligini tushundim. Shu yaxshiroq yechimning izohini beraman.
π‘ Medium: 2396. Strictly Palindromic Number
π¨βπ» Vazifa
Biz berilgan n sonining har bir base(2) dan base(n-2) gacha bo'lgan bo'lgan ko'rinishi palindrom bo'lishligini aniqlashimiz kerak.
Bu degani agar base(10) dagi 4 sonini olsak uning base(2) ko'rinishi "100" bo'ladi va, ko'rib turganingizdek, bu palindrom emas.
π¨βπ» Eng zo'r yechim:
Nimaga har doim false qaytaradi? Chunki berilayotgan har qanday sonning base(n-2) ko'rinishi "12" teng bo'lib qoladi va bu palindrom emas.
Keling base(10) dagi bo'lgan 21 sonining base(n-2) yoki base(19) ko'rinishini topamiz.
Boshida 21ni 19ga bo'lamiz: 21 / 19 = 1 va qoldiqda 2. Biz boshida "2" ni yozamiz, keyin esa "1" ni. Shunda "21" bo'ladi. Endi bu ko'rinishni orqadan oldinga yozamiz: "12". Ko'rganingizdek, biz 21 sonining base(19) da ko'rinishi "12" bo'lishini topdik. Bitta base-dan ikkinchi base-ga aylantirish qoidalari bu yerda: havola.
Base o'zbekchada nima bo'lishini yozvoringizlarπ
Yaxshi tushuntira oldim degan umiddaman!
Omad!βοΈ
Hammaga salom! Men o'zimning yechimimning izohini bermoqchi edim, ammo menikidan ancha yaxshiroq yechim borligini tushundim. Shu yaxshiroq yechimning izohini beraman.
π‘ Medium: 2396. Strictly Palindromic Number
π¨βπ» Vazifa
Biz berilgan n sonining har bir base(2) dan base(n-2) gacha bo'lgan bo'lgan ko'rinishi palindrom bo'lishligini aniqlashimiz kerak.
Bu degani agar base(10) dagi 4 sonini olsak uning base(2) ko'rinishi "100" bo'ladi va, ko'rib turganingizdek, bu palindrom emas.
π¨βπ» Eng zo'r yechim:
public boolean isStrictlyPalindromic(int n) {
return false;
}
π¨βπ» Izoh.Nimaga har doim false qaytaradi? Chunki berilayotgan har qanday sonning base(n-2) ko'rinishi "12" teng bo'lib qoladi va bu palindrom emas.
Keling base(10) dagi bo'lgan 21 sonining base(n-2) yoki base(19) ko'rinishini topamiz.
Boshida 21ni 19ga bo'lamiz: 21 / 19 = 1 va qoldiqda 2. Biz boshida "2" ni yozamiz, keyin esa "1" ni. Shunda "21" bo'ladi. Endi bu ko'rinishni orqadan oldinga yozamiz: "12". Ko'rganingizdek, biz 21 sonining base(19) da ko'rinishi "12" bo'lishini topdik. Bitta base-dan ikkinchi base-ga aylantirish qoidalari bu yerda: havola.
Base o'zbekchada nima bo'lishini yozvoringizlarπ
Yaxshi tushuntira oldim degan umiddaman!
Omad!βοΈ
LeetCode
Strictly Palindromic Number - LeetCode
Can you solve this real interview question? Strictly Palindromic Number - An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.
Given an integer n,β¦
Given an integer n,β¦
π8πΎ2β€βπ₯1
π¬π§ 706. Design HashMap
Hi, guys! I wrote several posts where I explained the way Hashtables work on a basic level. You can check those posts here: Hashtable.
Let's check how we mastered the basics of Hashtables.
π’ Easy: 706. Design HashMap
π¨βπ» My solution: Java | Built HashMap Based On Array
Please, try to build a HashMap on your own before checking solutions of other people.
As usual, explanation to be provided π.
Good luck!π€
Hi, guys! I wrote several posts where I explained the way Hashtables work on a basic level. You can check those posts here: Hashtable.
Let's check how we mastered the basics of Hashtables.
π’ Easy: 706. Design HashMap
π¨βπ» My solution: Java | Built HashMap Based On Array
Please, try to build a HashMap on your own before checking solutions of other people.
As usual, explanation to be provided π.
Good luck!π€
Telegram
LeetCodin
π¬π§ Hashtable. Sum up.
Hi, guys! Today I just want to leave links to all posts where I talked about Hashtable and its implementation in Java.
1οΈβ£ Hashtable - start
2οΈβ£ Hashtable. How to use.
3οΈβ£ Hashtable. Hashing.
4οΈβ£ Hashtable. Collision.
5οΈβ£ equals()β¦
Hi, guys! Today I just want to leave links to all posts where I talked about Hashtable and its implementation in Java.
1οΈβ£ Hashtable - start
2οΈβ£ Hashtable. How to use.
3οΈβ£ Hashtable. Hashing.
4οΈβ£ Hashtable. Collision.
5οΈβ£ equals()β¦
π3π1
πΊπΏ 706. Design HashMap
Hammaga salom! Men Hashtable ma'lumotlar tuzilmasini qanday ishlashi haqida postlar seriyasini yozgan edim. Postlarni bu yerda qarab chiqishingiz mumkin: Hashtable.
Keling Hashtable mavzusini qanchalik yaxshi o'zlashtirganligimizni tekshirib ko'raylik.
π’ Oson daraja: 706. Design HashMap
π¨βπ» Mening yechimim: Java | Built HashMap Based On Array
Iltimos, tayyor yechimga qarashdan avval, o'zingiz yaxshilab urinib ko'ring.
Har doimgidek, izohni keyingi postlarda kutamizπ.
Omad! π€
Hammaga salom! Men Hashtable ma'lumotlar tuzilmasini qanday ishlashi haqida postlar seriyasini yozgan edim. Postlarni bu yerda qarab chiqishingiz mumkin: Hashtable.
Keling Hashtable mavzusini qanchalik yaxshi o'zlashtirganligimizni tekshirib ko'raylik.
π’ Oson daraja: 706. Design HashMap
π¨βπ» Mening yechimim: Java | Built HashMap Based On Array
Iltimos, tayyor yechimga qarashdan avval, o'zingiz yaxshilab urinib ko'ring.
Har doimgidek, izohni keyingi postlarda kutamizπ.
Omad! π€
Telegram
LeetCodin
πΊπΏ Hashtable. Yakunlash.
Hammaga salom! Bugun sizlarga chiroyli qilib, Hashtable mavzusiga oid yozilgan post-larga havolalarni qoldiraman.
1οΈβ£ Hashtable - boshlanish.
2οΈβ£ Hashtable ishlatilishi.
3οΈβ£ Hashtable. Xeshlash.
4οΈβ£ Hashtable. Kolliziya.
5οΈβ£β¦
Hammaga salom! Bugun sizlarga chiroyli qilib, Hashtable mavzusiga oid yozilgan post-larga havolalarni qoldiraman.
1οΈβ£ Hashtable - boshlanish.
2οΈβ£ Hashtable ishlatilishi.
3οΈβ£ Hashtable. Xeshlash.
4οΈβ£ Hashtable. Kolliziya.
5οΈβ£β¦
π7π³1
π¬π§ 500 solved problems
Guys, I just wanted to share that I was able to achieve a new milestone today - 500 solved problem on LeetCode.
Yaaaay!π€
πΊπΏ 500 yechilgan masala
Sizlar bilan yana bitta muhim bosqichga erishganim bilan bo'lishmoqchiman - bu LeetCode-da yechilgan masalalarning soni 500ga yetdi!
Oldik!π₯
Guys, I just wanted to share that I was able to achieve a new milestone today - 500 solved problem on LeetCode.
Yaaaay!π€
πΊπΏ 500 yechilgan masala
Sizlar bilan yana bitta muhim bosqichga erishganim bilan bo'lishmoqchiman - bu LeetCode-da yechilgan masalalarning soni 500ga yetdi!
Oldik!π₯
π24πΎ10π1