After a long time, I’m finally back and I hope I’ll be able to post LeetCode solutions much often.
Yes I mentioned before that C++ is the best programming language for solving DSA problems, but that particular problem, I think would be solved in Python much easier (corresponding code there would be much less).
This is an interactive problem.
You are given an array of unique strings
6 letters long, and one word in this list is chosen as
You may call
Master.guess(word) to guess a word. The guessed word should have type
string and must be from the original list with
6 lowercase letters.
This function returns an
integer type, representing the number of exact matches (value and position) of your guess to the
secret word. Also, if your guess is not in the given wordlist, it will return
For each test case, you have exactly
10 guesses to guess the word. At the end of any number of calls, if you have made
10 or fewer calls to
Master.guess and at least one of these guesses was
secret, then you pass the test case.
Baada ya muda mrefu, mimi ni hatimaye nyuma na natumaini mimi itabidi kuwa na uwezo wa kuchapisha LeetCode ufumbuzi mara nyingi sana. C ++ ni lugha bora ya programu kwa ajili ya kutatua matatizo ya DSA, lakini tatizo hilo maalum, nadhani, itakuwa kutatuliwa katika Python rahisi zaidi (nambari inayolingana itakuwa chini sana). Hii ni tatizo maingiliano. "Kama unajua, kuna ""nambari"" ya herufi sita ambazo zinatumiwa kuashiria maneno ya kila aina, na kwa hivyo, kwa sababu ya kuashiria, unaweza kuchagua neno moja kutoka kwa orodha ya herufi sita, na kisha kuashiria neno moja kwa kila aina." Neno la kuaminika linapaswa kuwa na aina ya kamba na lazima liwe kutoka orodha ya awali na herufi ndogo 6. Kazi hii inarudi aina integer, kuwakilisha idadi ya mechi halisi (thamani na nafasi) ya dhana yako kwa neno siri. Kwa mfano, kama unafikiria neno la kwanza, utapata matokeo ya 10 kwa kila kesi ya jaribio. Baada ya simu 10 au chini, ikiwa unafanya simu 10 au chini kwa MasterGuess na angalau moja ya guesses hizi ilikuwa siri, basi unapita kesi ya mtihani.