# Union-Find (Disjoint Sets)

Scenario

Consider a social network site where people can become friends with one another. Friendship groups can be formed (person A is friends with person B, person B is friends with person C, person C is friends with person Z → the friendship group holds {A, B, C, Z}). You may want to see if you’re in the same friendship group with a specific person.

Friendship groups are basically graphs where each node represents a person and each edge represents a friendship. Each individual friendship group is basically a connected component.

Context

Before diving into the union-find (disjoint sets) data…

# Strings: Longest Palindromic Substring

As I start to continue to prepare for technical interviews, I’ll be going over solutions for questions that I find initially challenging. Today, I’ll be going over the Longest Palindromic Substring problem on Leetcode. The problem can be found here.

Problem Description

Given a string s, return the longest palindromic substring in s.

`Example 1:Input: s = "babad", Output: "bab", Note: "aba" is also a valid answer.Example 2:Input: s = "cbbd", Output: "bb"Example 3:Input: s = "a", Output: "a"`

Brute Force Solution

The naive way to solve this problem is to find all substrings by…

## Danny Pham

Software Development Engineer at Amazon

Get the Medium app