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..
Macha nen single for loop tho chesina🥳 li=[4,4,4,11,4,4,4,4,4,4] n=len(li) a=0 b=n-1 dist=0 dist1=0 for i in range(1,n): if li[a]!=li[i]: diff=abs(a-i) dist=max(dist,diff) if li[b]!=li[i]: diff1=abs(b-i) dist1=max(dist1,diff1) print(max(dist,dist1)) Output: 6
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...
class Solution: def maxDistance(self, colors: List[int]) -> int: n=len(colors) ans=0 for i in range(n): for j in range(n-1,-1,-1): if colors[i]!=colors[j]: temp=abs(j-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))
*******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
""81 test cases passed using this code"" class Solution: def maxDistance(self, colors: List[int]) -> int: ans=-1 low=0 for i in range(1,len(colors)): if low
Nuvvu cheppinattu 20mins alochincha macha brootforce lo vachindi naku without seeing the video idi kuda naku chala happy machaa but optimal way lo raledu😢 so appudu video chusa machaa
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
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)
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
bro first time nenu ni help thisukokunda solve chesina bruteforcelo feel happy bro.😍😍.
me also brother
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..
So far the best bro…. Great explanation… daily serial la follow avtunna 😅
Macha nen single for loop tho chesina🥳
li=[4,4,4,11,4,4,4,4,4,4]
n=len(li)
a=0
b=n-1
dist=0
dist1=0
for i in range(1,n):
if li[a]!=li[i]:
diff=abs(a-i)
dist=max(dist,diff)
if li[b]!=li[i]:
diff1=abs(b-i)
dist1=max(dist1,diff1)
print(max(dist,dist1))
Output: 6
macha super ga cheptunav bayya please bayya ee series apaiku python ki reach ravtaledu ani 🥲🥲
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...
class Solution:
def maxDistance(self, colors: List[int]) -> int:
n=len(colors)
ans=0
for i in range(n):
for j in range(n-1,-1,-1):
if colors[i]!=colors[j]:
temp=abs(j-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))
*******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
""81 test cases passed using this code""
class Solution:
def maxDistance(self, colors: List[int]) -> int:
ans=-1
low=0
for i in range(1,len(colors)):
if low
Nuvvu cheppinattu 20mins alochincha macha brootforce lo vachindi naku without seeing the video idi kuda naku chala happy machaa but optimal way lo raledu😢 so appudu video chusa machaa
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
Mawa on Fire🔥🔥
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)
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
keep going macha
Bro explain hard problems bro
Yes sure
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