I'm trying to pass a programming challenge where we are to replace all instances of a substring in a string until there are none left. So an input like
Pibabakekezza bake
Has output
Pizza
And if there is nothing left say so. I fail an unknown test case because I take longer than 1 second.
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
using System;
using System.Runtime;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Runtime.CompilerServices;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
GCLatencyMode oldMode = GCSettings.LatencyMode;
// Make sure we can always go to the catch block,
// so we can set the latency mode back to `oldMode`
RuntimeHelpers.PrepareConstrainedRegions();
try
{
GCSettings.LatencyMode = GCLatencyMode.LowLatency;
//Your code goes here
string s =Console.ReadLine();
string b =Console.ReadLine();
while(s.Contains(b))
{
s=s.Replace(b, "");
}
if(s!="")
{
Console.WriteLine(s);
}
else
{
Console.WriteLine("FRULA");
}
}
finally
{
// ALWAYS set the latency mode back
GCSettings.LatencyMode = oldMode;
}
}
}
}
Restrictions:
1≤|bigString|≤1 000 000
1≤|substring|≤36
bigString and the substring string consist of uppercase and lowercase letters of the English alphabet and digits 0, 1, …, 9. The characters in the substring are all different.
CPU Time limit: 1 second Memory limit: 1024 MB
the characters in the substring are all different
(you're not using this hint). When the string is fully browsed, all remaining characters are the answer. This doesn't even need to split/instantiate strings. Sorry, not proficient enough in C# to propose a full answer. \$\endgroup\$