Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
RHCSA, RHCE, AWS, Docker, Kubernetes Training
Sanjeewani95
Updated:
Tuesday at 10:28 AM
🛡️ Kaspersky Antivirus – 1 Year / 1 Device | Rs. 2,300 | Only 9 Left
KSPathirana
Updated:
Monday at 2:42 PM
Ad icon
Professional CCTV Installation Service
Techguy231
Updated:
Sunday at 10:50 AM
Ad icon
I'll research & write an article - Rs. 2000 onwards
Blogerwiki
Updated:
Sep 3, 2026
House Plan
lenura
Updated:
Sep 2, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
අනාත programmers ලා.
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="EKGuest" data-source="post: 28415822" data-attributes="member: 582168"><p>මට වුනෙත් ඔය දේම තමා. මම අන්තිමට ඉන්ටවීව් එකකට ගියේ 2009 දී. මගෙන් ඇහුවෙත් මේ වගේම ලේසි ප්රශ්න. ගිය හැම ඉන්ට්ටවීව් එකකදීම පැනික් වෙලා උත්තර දීගන්න බැරිව ගියා. ඊට පස්සෙ තමයි හිත හදාගෙන Developer ජොබ් හොයන එක නවත්තලා තාත්තා එක්ක වගා කරන්න පටන් ගත්තේ. ඒත් ප්රෝග්රෑමින් වලට ආස නිසා hobby එකක් විදියට දිගටම ෆ්රී වෙලාවල්වලට Coding Puzzles solve කරා.</p><p></p><p></p><p></p><p></p><p></p><p>I could only come up with a brute force solution for this problem. The output is correct but the solution is not efficient due to the use of brute force approach.</p><p></p><p>[CODE=csharp]using System;</p><p>using System.Collections.Generic;</p><p></p><p>internal class Program</p><p>{</p><p></p><p> static HashSet<string> FindAllPalindromes(string s)</p><p> {</p><p> HashSet<string> palindromes = new HashSet<string>();</p><p></p><p> for (int length = 1; length <= s.Length; length++)</p><p> {</p><p> for (int i = 0; i + length <= s.Length; i++)</p><p> {</p><p> if (IsPalindrome(s, i, i + length - 1))</p><p> palindromes.Add(s.Substring(i, length));</p><p> }</p><p> }</p><p></p><p> return palindromes;</p><p> }</p><p></p><p> static bool IsPalindrome(string s, int fromIndex, int toIndex)</p><p> {</p><p> while (fromIndex < toIndex)</p><p> {</p><p> if (s[fromIndex] != s[toIndex])</p><p> return false;</p><p> fromIndex++;</p><p> toIndex--;</p><p> }</p><p> return true;</p><p> }</p><p></p><p> static void Main(string[] args)</p><p> {</p><p> Console.Write("Input string: ");</p><p> string s = Console.ReadLine();</p><p> Console.WriteLine("\nList of all palindromes in the string:\n");</p><p></p><p> HashSet<string> palindromes = FindAllPalindromes(s);</p><p></p><p> foreach (string palindrome in palindromes)</p><p> Console.WriteLine(palindrome);</p><p> Console.ReadLine();</p><p> }</p><p></p><p>}</p><p>[/CODE]</p><p></p><p>[ATTACH=full]191553[/ATTACH]</p><p></p><p>An efficient solution can be found here: <a href="https://www.geeksforgeeks.org/find-number-distinct-palindromic-sub-strings-given-string/" target="_blank">Find all distinct palindromic sub-strings of a given string</a></p></blockquote><p></p>
[QUOTE="EKGuest, post: 28415822, member: 582168"] මට වුනෙත් ඔය දේම තමා. මම අන්තිමට ඉන්ටවීව් එකකට ගියේ 2009 දී. මගෙන් ඇහුවෙත් මේ වගේම ලේසි ප්රශ්න. ගිය හැම ඉන්ට්ටවීව් එකකදීම පැනික් වෙලා උත්තර දීගන්න බැරිව ගියා. ඊට පස්සෙ තමයි හිත හදාගෙන Developer ජොබ් හොයන එක නවත්තලා තාත්තා එක්ක වගා කරන්න පටන් ගත්තේ. ඒත් ප්රෝග්රෑමින් වලට ආස නිසා hobby එකක් විදියට දිගටම ෆ්රී වෙලාවල්වලට Coding Puzzles solve කරා. I could only come up with a brute force solution for this problem. The output is correct but the solution is not efficient due to the use of brute force approach. [CODE=csharp]using System; using System.Collections.Generic; internal class Program { static HashSet<string> FindAllPalindromes(string s) { HashSet<string> palindromes = new HashSet<string>(); for (int length = 1; length <= s.Length; length++) { for (int i = 0; i + length <= s.Length; i++) { if (IsPalindrome(s, i, i + length - 1)) palindromes.Add(s.Substring(i, length)); } } return palindromes; } static bool IsPalindrome(string s, int fromIndex, int toIndex) { while (fromIndex < toIndex) { if (s[fromIndex] != s[toIndex]) return false; fromIndex++; toIndex--; } return true; } static void Main(string[] args) { Console.Write("Input string: "); string s = Console.ReadLine(); Console.WriteLine("\nList of all palindromes in the string:\n"); HashSet<string> palindromes = FindAllPalindromes(s); foreach (string palindrome in palindromes) Console.WriteLine(palindrome); Console.ReadLine(); } } [/CODE] [ATTACH type="full" alt="1.png"]191553[/ATTACH] An efficient solution can be found here: [URL='https://www.geeksforgeeks.org/find-number-distinct-palindromic-sub-strings-given-string/']Find all distinct palindromic sub-strings of a given string[/URL] [/QUOTE]
Insert quotes…
Verification
Payakata winadi keeyak tibeda?
Post reply
Top
Bottom