en
Feedback

Don't get caught by a cheater! Telemetrio finds and tags such channels πŸ‘‰ If you want to see the tag, subscribe

Leetcode with dani

Leetcode with dani

Open in Telegram

Join us and let's tackle leet code questions together: improve your problem-solving skills Preparing for coding interviews learning new algorithms and data structures connect with other coding enthusiasts

Show more
1 240
Subscribers
-124 hours
-37 days
-1730 days
Posts Archive
Hey there! How did you do on the sqrt problem?
Anonymous voting
03 Jun 2024, 02:30

dont use built-in function πŸ˜…
02 Jun 2024, 11:42

69. Sqrt(x) #binary_search #Easy #leet_code_Q9 Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or operator. For example, do not use pow(x, 0.5) in c++ or x ** 0.5 in python. Example 1: Input: x = 4 Output: 2 Explanation: The square root of 4 is 2, so we return 2. Example 2: Input: x = 8 Output: 2 Explanation: The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned
02 Jun 2024, 11:41

πŸ”°Complete DSA RoadmapπŸ”° |-- Basic_Data_Structures | |-- Arrays | |-- Strings | |-- Linked_Lists | |-- Stacks | └─ Queues | |-- Advanced_Data_Structures | |-- Trees | | |-- Binary_Trees | | |-- Binary_Search_Trees | | |-- AVL_Trees | | └─ B-Trees | | | |-- Graphs | | |-- Graph_Representation | | | |- Adjacency_Matrix | | | β”” Adjacency_List | | | | | |-- Depth-First_Search | | |-- Breadth-First_Search | | |-- Shortest_Path_Algorithms | | | |- Dijkstra's_Algorithm | | | β”” Bellman-Ford_Algorithm | | | | | └─ Minimum_Spanning_Tree | | |- Prim's_Algorithm | | β”” Kruskal's_Algorithm | | | |-- Heaps | | |-- Min_Heap | | |-- Max_Heap | | └─ Heap_Sort | | | |-- Hash_Tables | |-- Disjoint_Set_Union | |-- Trie | |-- Segment_Tree | └─ Fenwick_Tree | |-- Algorithmic_Paradigms | |-- Brute_Force | |-- Divide_and_Conquer | |-- Greedy_Algorithms | |-- Dynamic_Programming | |-- Backtracking | |-- Sliding_Window_Technique | |-- Two_Pointer_Technique | └─ Divide_and_Conquer_Optimization | |-- Merge_Sort_Tree | └─ Persistent_Segment_Tree | |-- Searching_Algorithms | |-- Linear_Search | |-- Binary_Search | |-- Depth-First_Search | └─ Breadth-First_Search | |-- Sorting_Algorithms | |-- Bubble_Sort | |-- Selection_Sort | |-- Insertion_Sort | |-- Merge_Sort | |-- Quick_Sort | └─ Heap_Sort | |-- Graph_Algorithms | |-- Depth-First_Search | |-- Breadth-First_Search | |-- Topological_Sort | |-- Strongly_Connected_Components | └─ Articulation_Points_and_Bridges | |-- Dynamic_Programming | |-- Introduction_to_DP | |-- Fibonacci_Series_using_DP | |-- Longest_Common_Subsequence | |-- Longest_Increasing_Subsequence | |-- Knapsack_Problem | |-- Matrix_Chain_Multiplication | └─ Dynamic_Programming_on_Trees | |-- Mathematical_and_Bit_Manipulation_Algorithms | |-- Prime_Numbers_and_Sieve_of_Eratosthenes | |-- Greatest_Common_Divisor | |-- Least_Common_Multiple | |-- Modular_Arithmetic | └─ Bit_Manipulation_Tricks | |-- Advanced_Topics | |-- Trie-based_Algorithms | | |-- Auto-completion | | └─ Spell_Checker | | | |-- Suffix_Trees_and_Arrays | |-- Computational_Geometry | |-- Number_Theory | | |-- Euler's_Totient_Function | | └─ Mobius_Function | | | └─ String_Algorithms | |-- KMP_Algorithm | └─ Rabin-Karp_Algorithm | |-- OnlinePlatforms | |-- LeetCode | |-- HackerRank Groups & Friends too
01 Jun 2024, 14:09
01 Jun 2024, ~14:09

In python, what does the enumerate() function do?
Anonymous voting
01 Jun 2024, 14:01

photo content
01 Jun 2024, 13:54

I will be posting python question's daily beside leetcode question
01 Jun 2024, 13:49

new comers hands up πŸ™Œ
01 Jun 2024, 13:46

Approach 2: using Binary Search :
class Solution: def arrangeCoins(self, n: int) -> int: left = 1 right = n while (left <= right): mid = (left + right) // 2 total =( (mid) * (mid + 1) )/ 2 if total == n: return mid if total >n: right = mid - 1 else: left = mid + 1 return left - 1
01 Jun 2024, 13:45

Approach 1 : using Brute Force Method Answer :
 class Solution:
    def arrangeCoins(self, n: int) -> int:
        while (True):
            i =  1
            total =( (i) * (i + 1) )/ 2
            if total > n:
                return i-1:
           else:  i+=1
01 Jun 2024, 13:45

let's write the code and submit.
01 Jun 2024, 13:23

But since it has O(N) time complexity, we need to find a more efficient approach. This is where binary search comes in handy. By using binary search with left = 1 and right = the number of coins, we can cut the array size in half each time and find the answer with O(logN) time complexity.
01 Jun 2024, 13:23

Let's say n is the number of stairs and c is the number of coins. Based on this, we can iterate from 1 up to n, where (n+1 * n) / 2 > c. When we find the first n that fulfills this condition, we subtract 1 so that n is the maximum number of stairs that we can build with the given number of coins.
01 Jun 2024, 13:15

First, how can we determine the number of coins that are enough for building an n-staircase? Let's look at an example: to build 1 stair, we need 1 coin; for 2 stairs, we need 3 coins; for 3 stairs, we need 5 coins; and for 4 stairs, we need 10 coins. What do you notice from this pattern? The number of stairs and the number of coins have a relationship, so we can use the formula (n+1 * n) / 2 to calculate the number of coins needed based on the number of stairs.
01 Jun 2024, 13:14

let's solve the question.
01 Jun 2024, 13:01

Have you found the solution to the arranging coin problem ?
Anonymous voting
01 Jun 2024, 09:15

Have you found the solution to the arranging coin problem ?
Anonymous voting
01 Jun 2024, 09:08
01 Jun 2024, ~09:13

You can contact me if you have any comments, ideas, questions, or anything to talk about https://t.me/zprogramming_bot
01 Jun 2024, 06:37

Input: n = 8 Output: 3 Explanation: Because the 4th row is incomplete, we return 3
Input: n = 8 Output: 3 Explanation: Because the 4th row is incomplete, we return 3
01 Jun 2024, 02:14

Input: n = 5 Output: 2 Explanation: Because the 3rd row is incomplete, we return 2.
Input: n = 5 Output: 2 Explanation: Because the 3rd row is incomplete, we return 2.
01 Jun 2024, 02:13