[LeetCode]#2078. Two Furthest Houses With Different Colors

Input: colors = [1,1,1,6,1,1,1]
Output: 3
Explanation: In the above image, color 1 is blue, and color 6 is red.
The furthest two houses with different colors are house 0 and house 3.
House 0 has color 1, and house 3 has color 6. The distance between them is abs(0 - 3) = 3.
Note that houses 3 and 6 can also produce the optimal answer.
  1. Use enumerate find location and number in list.
  2. Check location 0 number is equal or not.
  3. If yes, distance is 0.
  4. If yes location index -0.
  5. output max one.
class Solution:
def maxDistance(self, colors):
for i,j in enumerate(colors):
for a,b in enumerate(colors):
if j!=b:
if abs(i-a)>d:
return d

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

When using third-party libraries…

Getting To Know Docker | Part 2: Web App Boogaloo

The Importance of Monitoring Your FOSS Licenses

Migrations, controllers, routes, and more with ruby on rails.

Launching 619 thousand Tetris on GPU, their rendering, and a simple bot

My journey in tech so far

Serverless Stack for Mobile Application Development

Toss2Win Analysis — A Newbie’s crack at Cricket Analytics

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

[LeetCode]#2085. Count Common Words With One Occurrence

Python Interview Questions for 2022

LeetCode Patterns Adventure 7 — Maximum Subarray

Interview Tips: How to use Lists efficiently in Python