Daily Leetcode Challenge | NOV 11 | HINDI | Prime Subtraction Operation

preview_player
Показать описание
Daily Leetcode Challenge- November 2024 - Day 11 - Prime Subtraction Operation

Approach/Topic : optimal way to find if a number is prime

optimized approach beats 90% of the test cases

Like, share and subscribe
***********************
Hi, I am a SDE , at one of the Fortune 50 companies!!

The intent of this channel is to motivate the community to code everyday, and also to make their coding rounds-during interview, a bit easier !! :)

Every question has a 1)brute-force approach 2)optimized approach, and the language used is simple English

I try my best to keep my solutions beginner friendly and simple to understand.

thanks for your support!! :)
***********************

Leetcode Today Challenge,
Daily Coding Practise,
Leetcode 100 days of code,
Python Daily Coding Challenge,
Daily LeetCoding Challenge ,
daily leetcode challenge,
daily leetcode questions,
daily leetcode problem,
leetcode daily today,
leetcode daily problem today,
leetcode daily challenge,
leetcode daily practise,
leetcode solutions,
letcode python,
leetcode hard problems,
leetcode easy problems,
leetcode medium problems,
leetcode for begineers,
leetcode python problems,
leetcode python,
leetcode python solutions,
leetcode python hard,
leetcode python medium,
leetcode python easy,
leetcode python english,
leetcode python solutions in english
Where to learn dp
where to learn graphs
where to learn dsa
how to start programming
how to start coding
where to learn trees
what is memoisation
what is tabulation
what are graphs
where to learn Operating systems
where to learn dbms
where to learn oops
where to learn computer networks
where to learn low level design
where to learn cs fundamentalS
Gate smashers
Placement guide
How to start programming
where to learn cpp
where to learn python
where to learn javascript
where to learn java
Placement guide
languages to learn
resources to learn data structures
Projects development
Software developer engineer ,
Importance of side projects ,
How to become a machine learning engineer ,
Associate engineer
Data structures Algorithms
College Life, College, Memories
Where to learn dp
where to learn graphs
where to learn dsa
how to start programming
how to start coding
where to learn trees
what is memoization
what is tabulation
what are graphs
where to learn programming
how to start coding
where to learn coding
where to learn DSA
resources to learn programming
how to crack amazon
how to crack placement
what is blockchain
blockchain technology explained
blockchain technology in hindi
web development roadmap
android development roadmap
MERN stack roadmap
roadmap for 2nd years
roadmap for opensource
roadmap for ios development
roadmap to learn DSA
microsoft internship,
microsoft intern 2022,
microsoft internship India,
microsoft internship experience
microsoft,software engineer

#leetcode #leet_preparation_tips #leetcodesolution #coding #interview
#CodingInterview #NovemberLeetCodingChallenge #Google #Amazon #programming #march #codinglife #meta #faang #maang
Рекомендации по теме
Комментарии
Автор

class Solution:
def primeSubOperation(self, nums: List[int]) -> bool:
#get prime nos from 1-1000
prime=set([2, 3, 5, 7, 11, 13, 17, 19, 23, 29])
maxx=max(nums)
n=len(nums)
for i in range(30, maxx):
for j in range(2, ceil(i**(0.5)+1)):
if(i%j==0):
break
else:
prime.add(i)

def
nonlocal prime
if(num<=2):
return -1
# this for loop will run from num-1 to 2
for i in range(num-1, 1, -1):
if(i in prime):
return i
return -1
#0th ele


print(f"subtracting {largestEligiblePrime} from {nums[0]}")

print(0, nums)
for i in range(1, n):
#print(i, nums)
if(nums[i]<=nums[i-1]):
return False
diff=nums[i]-nums[i-1]


print(f"subtracting {largestEligiblePrime} from {nums[i]}")

print(i, nums)




return True

# n=100
# to check if its prime, start from 2->sqrt(100) ie: 2->10

# 2*50
# 5*20
# 10*10

# [4, 9, 6, 10]
# [1, 2, 3, 5]

# 4-3
# 9-1=8
# 9-7=2
# 6-2=4
# 6-3=3
# 10-3=7
# 10-5=5

darshankumar