iwbr
BAN USERIf this is a repititive operation we can save the dictionary in memory.
public Dictionary<string, int> FindNumberOfMostLogins(string input, int minNoOfLogins)
{
Dictionary<string,int> dict=new Dictionary<string, int>();
string[] userNames= input.Split(',');
foreach (var username in userNames)
{
if (!dict.ContainsKey(username))
dict.Add(username, 1);
else
dict[username] += 1;
}
return dict.Where(x => x.Value >= minNoOfLogins).ToDictionary(x => x.Key, x => x.Value);
}
- iwbr June 07, 2016public class PaintRange
{
public int first;
public int last;
public int cost;
public PaintRange(int first, int last, int cost)
{
this.first = first;
this.last = last;
this.cost = cost;
}
}
public class PaintRangeBlack
{
public int FindMinimumCost(int first, int last, int cost, List<PaintRange> ranges)
{
int minCost = Int32.MaxValue;
int oldcost = cost;
foreach (var range in ranges)
{
if (range.first <= first && range.last > first)
{
if (minCost == Int32.MaxValue || cost + range.cost < minCost)
{
cost += range.cost;
if (range.last < last)
{
int temp = FindMinimumCost(range.last, last, cost, ranges);
if (temp != Int32.MaxValue && minCost>temp)
minCost = temp;
}
if (range.last >= last && minCost > cost)
{
minCost = cost;
cost = oldcost;
}
}
}
cost = oldcost;
}
return minCost;
}
}
- iwbr June 07, 2016
do we just need to find all sub strings from string that are present in dictionary, if yes then it is really simple. Am i missing something here ?
- iwbr August 16, 2016