p.rubanantony
BAN USERNot sure my understanding of the problem is correct.
int[] array = new int[] { 2, 3, 30, 45, 6, 7, 8, 3, 25, 5 };
Suppose k = 9
Then the output should be 3
Subarrays all elements less than 9 = {2,3}, {6,7,8,3}, {5}
private int SubArrayCount(int[] array, int k)
{
int count = 0;
int length = array.Length;
for (int i = 0; i < length; i++)
{
if (array[i] < k)
{
while (i < length && array[i] < k)
i++;
count++;
}
}
return count;
}
Simple Solution C#: (Tested)
public bool CanBreak(string s, Dictionary<string, int> frequency)
{
string temp = s;
foreach (string word in frequency.Keys)
{
int count = 0;
int index = 0;
temp = s;
while (index >= 0 && count <= frequency[word])
{
index = temp.IndexOf(word);
if (index == -1)
{
return false;
}
count++;
temp = s.Substring(index + word.Length - 1);
}
}
return true;
}
- p.rubanantony June 14, 2020