Leetcode with dani – Telegram
Leetcode with dani
1.31K subscribers
196 photos
14 videos
56 files
240 links
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
Download Telegram
Question 1 (Multiple Choice):

What happens if the user enters "twenty-five" instead of a number when prompted for their age using age = int(input("Enter your age: "))? .
Anonymous Quiz
67%
A. The program crashes with an error.
21%
B. The program stores "twenty-five" as the user's age.
13%
C. The program converts "twenty-five" to 25 automatically
🏆1
number_string = "1234"
number = int(number_string)
print(number + 5)
Anonymous Quiz
27%
12345
57%
1239
16%
Error
👍2
Hey everyone,

Big news! This channel is evolving to focus on cracking LeetCode problems and sharpening your coding skills.

While I appreciate your interest in Python, I'm excited to embark on this new journey with you all, tackling LeetCode challenges together.

Why LeetCode?

Boost your coding interview skills: LeetCode problems are widely used by top tech companies, and mastering them will put you ahead of the curve.
Test and improve your problem-solving abilities: LeetCode offers a variety of problems ranging from easy to challenging, ensuring there's something for everyone.
Learn from each other: We can discuss solutions, share different approaches, and help each other overcome obstacles.
Get ready to:

Dive into LeetCode problems (all levels): We'll tackle a variety of challenges, from basic algorithms to more complex data structures.
Collaborate and discuss solutions: Share your thought processes, learn from different approaches, and help each other conquer the problems.
Become a LeetCode master: Together, we'll push ourselves and improve our coding skills to new heights.
Are you ready to join the LeetCode challenge?

Let's make this channel a hub for collaboration and LeetCode problem-solving!

P.S. Feel free to suggest specific LeetCode problems you'd like to tackle in the comments below.

Let's code together! let me know your ideas in the comment section and there is another group i created only for python i will post it below.
🔥4
#leet_code_Q1 #Array Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

You must implement a solution with a linear runtime complexity and use only constant extra space.



Example 1:

Input: nums = [2,2,1]
Output: 1
Example 2:

Input: nums = [4,1,2,1,2]
Output: 4
Example 3:

Input: nums = [1]
Output: 1 Each element in the array appears twice except for one element which appears only once.
👍4
Channel name was changed to «Leet code with dani»
Leetcode with dani pinned «#leet_code_Q1 #Array Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with a linear runtime complexity and use only constant extra space. Example 1: Input: nums…»
Hint2: try Xor operation
lets submit our code
it's good. we did better from 78 % of submitted code in python by running time
🏆3
Level Up Problem-Solving: LeetCode trains your brain to break down problems, a skill used by 80% of software engineers according to a [Payscale survey]( Indeed salary survey for Software Engineer).
lets do another Question on Leet code
#leet_code_Q2 #Array #leet_code_169 #Majority_Element Given an array nums of size n, return the majority element.

The majority element is the element that appears more than (n / 2)times. You may assume that the majority element always exists in the array.

Example 1:

Input: nums = [3,2,3]
Output: 3
Example 2:

Input: nums = [2,2,1,1,1,2,2]
Output: 2
Let's tackle the question of finding the number that appears only once in a list.

if you want to figure it out your self, dont see the answer!!!!!!!!!!!!!!!!!!

We could iterate through the list, comparing each element to all others to count occurrences. This approach would work, but it has a time complexity of n^2, exceeding the given constraint of linear time (O(n)).



Since the question guarantees that all other elements appear twice, we can exploit this property. Here's how:



Convert the list to a set. Sets eliminate duplicates, leaving only the unique element.

Calculate the sum of the elements in the original list and the set.

Unique number = Sum of list elements - (2 * Sum of set elements)

This method efficiently finds the unique element in linear time.



There's an even better approach called the XOR method. If you'd like an explanation of how it works, I can provide the code and break it down for you class Solution:

def singleNumber(self, nums: List[int]) -> int:

result = 0

for i in nums:

result^=i

return result
👍1