Ayush7614 / Daily-Coding-DS-ALGO-Practice

A open source project🚀 for bringing all interview💥💥 and competative📘 programming💥💥 question under one repo📐📐
https://daily-ds-algo.github.io/DS-Algo-Website/
MIT License
320 stars 476 forks source link

Spy-string #200

Open palakagarwal5230 opened 3 years ago

palakagarwal5230 commented 3 years ago

Problem; You are given n strings a1,a2,…,an: all of them have the same length m. The strings consist of lowercase English letters.

Find any string s of length m such that each of the given n strings differs from s in at most one position. Formally, for each given string ai, there is no more than one position j such that ai[j]≠s[j].

Note that the desired string s may be equal to one of the given strings ai, or it may differ from all the given strings.

Example: if you have the strings abac and zbab, then the answer to the problem might be the string abab, which differs from the first only by the last character, and from the second only by the first.

Input The first line contains an integer t (1≤t≤100) — the number of test cases. Then t test cases follow.

Each test case starts with a line containing two positive integers n (1≤n≤10) and m (1≤m≤10) — the number of strings and their length.

Then follow n strings ai, one per line. Each of them has length m and consists of lowercase English letters.

Output Print t answers to the test cases. Each answer (if it exists) is a string of length m consisting of lowercase English letters. If there are several answers, print any of them. If the answer does not exist, print "-1" ("minus one", without quotes).

Programming language

palakagarwal5230 commented 3 years ago

I am a LGM-SOC'21 Participant and has opened this issue. I want to write c++ solution to it. This problem is from codeforces .

Amit366 commented 3 years ago

@palakagarwal5230 for this create a separate folder named Codeforces and then add it.

Amit366 commented 3 years ago

@palakagarwal5230 for this create a separate folder named Codeforces and then add it.

palakagarwal5230 commented 3 years ago

@palakagarwal5230 for this create a separate folder named Codeforces and then add it.

Okay thank you.