Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimize this code for large input
    primarykey
    data
    text
    <p>i have this solution that works for smaller inputs say an input string of length up to 350,beyond that it gives runtime error.input constraint is 0 &lt; input&lt;500 .</p> <p>this problem is from <a href="https://www.hackerrank.com/contests/quantium/challenges/k-mismatch" rel="nofollow">https://www.hackerrank.com/contests/quantium/challenges/k-mismatch</a></p> <p>how can i optimize this code to handle strings up to length 500?</p> <p>Language c#</p> <pre><code> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Solution { static int mismatch(string a, string b) { int result = 0; for (int i = 0; i &lt; a.Length; i++) if (a[i] != b[i]) result++; return result; } static void Main(string[] args) { long no = 0; int K = int.Parse(Console.ReadLine()); string word = Console.ReadLine(); List&lt;string&gt; wordList = new List&lt;string&gt;(); List&lt;string&gt; curr = new List&lt;string&gt;(); var query = from i in Enumerable.Range(0, word.Length) from j in Enumerable.Range(0, word.Length - i + 1) where j &gt;= 1 select word.Substring(i, j); for (int i = 1; i &lt; word.Length; i++) { foreach (string s in query) { if (s.ToString().Length == i)curr.Add(s); } if (curr.Count() &gt; 1) for (int j = 0; j &lt; curr.Count(); j++) for (int k = j + 1; k &lt; curr.Count(); k++) if (mismatch(curr.ElementAt(j).ToString(), curr.ElementAt(k).ToString()) &lt;= K) no++; curr.Clear(); } Console.WriteLine(word.Length+":"+no); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload