LeetCode Problem | part 18 | DSA in python in telugu | Engineering Animuthyam
HTML-код
- Опубликовано: 29 сен 2024
- Free python dsa course in Telugu | Engineering Animuthyam
Free python dsa course in Telugu
Website link:
vigneshreddyjulakanti.in/python
Insta:
Engineering Animuthyam
python dsa
dsa python
python in telugu
telugu python
Dsa in telugu
from scratch
easy
hd
simple
telugu engineering
dsa
coding
programming
engineering
engineering animuthyam.
jobs
high paying jobs
road maps
Dsa in telugu
Mern stack
Python
Java
M1
Daa
Placements
Btech
IIt
Nit
Eamcet
#coding #telugu #job #python #telugumemes #trendingreels #btech #college #java #javacoding #iit #pythontutorialtelugu
#nit #jee #eamcet #dsa
Bro super ga cheptunnav nak IT lo 2+ exp unna eppativaru chusina vallalo superb ra cheptunnav bro nen chala vedios chusa enta basic ga yevaru cheppaled bro..go head🎉 content kasta fast ga update cheyyi..
bro first time nenu ni help thisukokunda solve chesina bruteforcelo feel happy bro.😍😍.
Arey broo.. nenu brute force radhamani alochincha but fortunately o(n) lo rayagaliga ... then ee video ki vachi chusthe nuvvu same nenu use chesina logic ey use chesav ... I'm Peeling great...
anna naku ila chesthe answer vachindhi anni test cases kuda pass aindhi em kada (optimal method)
colors=[1,1,1,6,1,1,1]
ans=0
n=len(colors)
for i in range(n):
if colors[0]!= colors[i] and i!=0:
dif=abs(0-i)
ans=max(ans,dif)
if colors[i]!=colors[n-1]:
dif=abs(i-(n-1))
ans=max(ans,dif)
print(ans)
So far the best bro…. Great explanation… daily serial la follow avtunna 😅
*******Optimal way******
l=[4,4,4,11,4,4,11,4,4,4,4,4]
n=len(l)
ans=0
for i in range(0,n-1):
if l[i]!=l[n-i-1]:
temp=abs(i-(n-i))
ans=max(ans,temp)
return ans
colors = [4,4,4,11,4,4,11,4,4,4,4,4]
for i in range(len(colors)-1,0,-1):
if colors[i] != colors[0] :
max_dis = i - 0
break
for i in range(len(colors)):
if colors[i] != colors[ len(colors)-1 ] :
max_dis1 = len(colors)-1 - i
break
print(max(max_dis,max_dis1))
My solution
First Approach:O(N sqaure)
class Solution:
def maxDistance(self, colors: List[int]) -> int:
r=len(colors)
maximum=0
res=0
for i in range(r):
for j in range(r):
if(colors[i]!=colors[j]):
res=abs(i-j)
maximum=max(maximum,res)
return maximum
Optimal code: O(N)
class Solution:
def maxDistance(self, colors: List[int]) -> int:
r=len(colors)
first=colors[0]
last=colors[-1]
Ans=0
Ans1=0
Ans2=0
maxnum=0
for i in range(r):
if first!=last:
Ans=r-1
maxnum=Ans
break;
if first!=colors[i]:
Ans1=max(Ans1,abs(i-0))
maxnum=max(Ans2,maxnum)
if last!=colors[i]:
Ans2=max(Ans2,abs(i-(r-1)))
maxnum=max(Ans2,Ans1)
return maxnum
keep going macha
macha super ga cheptunav bayya please bayya ee series apaiku python ki reach ravtaledu ani 🥲🥲
Bro nenu e question ki code mundhe solve chesa website lo question open chesi . Parledhu improve ayya 0 nuche antho kontha logic wise. Optimize solution kosam vacha bro eroju
Ewwwww 🔥🔥🔥🔥
Ela.rasa bro nenu logic 😊
n=len(colors)
ans=0
for i in range(n):
for j in range(1,n):
if colors[j]>colors[i]:
temp=abs(i-j)
ans=max(temp,ans)
return ans
Vere level 🔥🔥@@Swajyoram
Bro please give us roadmap of your way of doing conding form 1st year and how did you become good in coding
I made a video on my journey in thid channel once chek it
@@engineeringanimuthyam ok bro thanks
Bro explain hard problems bro
Yes sure