vh.vahan
BAN USER
The complexity is o(n^2)
create dictionary where key is Y coordinate and values are Hashset of X coordinates.
public struct Point
{
public int X { get; set; }
public int Y { get; set; }
public Point(int x, int y)
{
X = x;
Y = y;
}
}
public static int RectanglesCount(List<Point> points)
{
Dictionary<int, HashSet<int>> dic = new Dictionary<int, HashSet<int>>();
foreach (var item in points)
{
if (dic.ContainsKey(item.Y))
dic[item.Y].Add(item.X);
else
dic.Add(item.Y, new HashSet<int>() { item.X });
}
int cnt = 0;
int[] ycoords = dic.Keys.OrderBy(i => i).ToArray();
for (int i = 0; i < ycoords.Length; i++)
{
for (int j = i+1; j < ycoords.Length; j++)
{
cnt += dic[i].Intersect(dic[j]).Count() / 2;
}
}
return cnt;
}
public struct Point
{
public int X { get; set; }
public int Y { get; set; }
public Point(int x, int y)
{
X = x;
Y = y;
}
}
public static int RectanglesCount(List<Point> points)
{
Dictionary<int, HashSet<int>> dic = new Dictionary<int, HashSet<int>>();
foreach (var item in points)
{
if (dic.ContainsKey(item.Y))
dic[item.Y].Add(item.X);
else
dic.Add(item.Y, new HashSet<int>() { item.X });
}
int cnt = 0;
int[] ycoords = dic.Keys.OrderBy(i => i).ToArray();
for (int i = 0; i < ycoords.Length; i++)
{
for (int j = i+1; j < ycoords.Length; j++)
{
cnt += dic[i].Intersect(dic[j]).Count() / 2;
}
}
return cnt;
}
Time O(n)
public class Node
{
public int Value { get; set; }
public Node Next { get; set; }
}
public class SinglyLinkedList
{
public Node Head { get; set; }
public Node Tail { get; set; }
public int Count { get; set; }
}
public static bool IsPolindrom(SinglyLinkedList list)
{
Stack<int> store = new Stack<int>();
Node current = list.Head;
for (int i = 0; i < list.Count; i++)
{
if (i <= list.Count / 2)
store.Push(current.Value);
else
{
int tmp = store.Pop();
if (tmp != current.Value)
return false;
}
current = current.Next;
}
return true;
}
Use BitArray, because of the limited memory requirement
BitArray store = new BitArray(10000000, false);
int num = GetNum();
while (num != -1)
{
if (!store.Get(num - 1))
store.Set(num - 1, true);
num = GetNum();
}
for (int i = 0; i < store.Length; i++)
{
if (store.Get(i))
Console.WriteLine(i + 1);
}
public class AccountHackHelper
{
int n;
SortedList<DateTime, DateTime> store;
public AccountHackHelper(int n)
{
this.n = n;
store = new SortedList<DateTime, DateTime>(n);
}
public bool IsAccountHacked(string userName, DateTime currentDate)
{
StoreFailedLogin(currentDate);
if (store.Count == n && (currentDate - store.First().Value).TotalSeconds < 3600 )
{
return true;
}
return false;
}
private void StoreFailedLogin(DateTime currentDate)
{
if (store.Count == n) { store.RemoveAt(0); }
store.Add(currentDate, currentDate);
}
}
RepEllenaSimon, Animator at ABC TECH SUPPORT
Hello I am an event planner and I have been working in this field for almost 5 years. For a ...
RepYuvaanSmith, Analyst at ADP
Monitor and coordinate project information as it relates to the finances of the organization both before, during, and after bringing ...
RepJesseCarlson, Cloud Support Associate at Alfa Chemaical Laboratory
Jesse , a video producer with 4 years of experience in running production processes from start to finish. Excellent at client ...
Repjoycejflora, Android Engineer at ABC TECH SUPPORT
I am excited about cooperation and interesting projects. Last year I work for a person who provides the black magic ...
RepStanPhillips, Animator at AMD
StanPhillips, a Landscape architect . I have been working at Pro Property Maintenance it's almost 10 years . I also help ...
Repjonej8821, Blockchain Developer at Alliance Global Servies
I am EbonyTuckson .I am a teacher who works in High school. I work during school hours but may also ...
RepCrystalKeane, Android test engineer at ABC TECH SUPPORT
Hello I am a skill trainer. Master's Degree in Industrial and Organisational Psychology and 10 years of experience working ...
RepYaniraBryant, Accountant at CGI-AMS
I am Yanira , a writer by fate. Went from writing for media outlets to exploring the world of content creation ...
RepKeciaFowler, Area Sales Manager at Auto NInja
My name is Kecia and I am a results-oriented Real Estate Appraiser Trainee with a strong determination to perform great ...
RepOniScott, Analyst at Agilent Technologies
Dedicated and energetic bakery assistant with a passion for flavor and a love for creating.Excellent at managing several tasks ...
RepRhondaLillie, Android test engineer at AppNexus
I work as an General and operations manager at the Official All Star Café. presenting love stories, ghost stories. Currently ...
RepEzraDavis, abc at A9
I am a hardworking and disciplined newly-certified architect with internship experience in designing commercial buildings and creating accurate 2D and ...
RepDeanSims, Associate at ASU
DeanSims a hardworking Tire builder . expert in this work working at Magna Architectural Design . I am also a part of ...
- vh.vahan February 15, 2017