• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
January 17, 2024 |660 Views
SDE Sheet - Circle of Strings
  Share  1 Like
Description
Discussion

This video is part of Graph section under GFG SDE Sheet.

In this problem, we are given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle.
A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one with the first character and second with the last character of the string), it will form a circle.

For example, for the array arr[] = {"for", "geek", "rig", "kaf"} the answer will be Yes as the given strings can be chained as "for", "rig", "geek" and "kaf"

Example :

Input:
N = 3
A[] = { "abc", "bcd", "cdf" }
Output:
0
Explaination:
These strings can't form a circle because no string has 'd'at the starting index.

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-
Article: https://www.geeksforgeeks.org/given-array-strings-find-strings-can-chained-form-circle/
Problem: https://www.geeksforgeeks.org/problems/circle-of-strings/0
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More