MessyHack
BAN USER
Dictionary<int, int> counts = new Dictionary<int, int>();
int[] input = { 1, 6, 4, 1, 4, 5, 8, 8, 4, 6, 8, 8, 9, 7, 9, 5, 9 };
foreach( int i in input)
{
int count;
if (counts.TryGetValue(i, out count))
{
counts[i] = i ^ count;
}
else
{
counts[i] = i;
}
}
foreach( var pair in counts)
{
if ( pair.Value == 0 )
{
Console.WriteLine(pair.Key);
}
}
assuming the cpu has multiple processors
three threads, 1 hashtable (or trie), 1 queue --
thread #1:
read from file #1 (treat the long ints as strings )
insert the long int into a hashtable, key is the #, value is a bool.
if the # is already in the table, check the bool to see if it's been queue'd for writing.
if it hasn't, add the # to a queue, set the bool to true
thread #2
same as thread #1, except it reads from file #2
thread #3
deque a # from the queue, write it to file
when thread #1 is finished and thread #2 is finished and the queue is empty...
done.
access to the hashtable and queue need to be sync'd across threads.
assuming the file is on disk; most of the time is going to spent in reading/writing files,
so breaking that work up across multiple threads is ideal (assuming the files are large).
The memory usage might be too high with a hashtable;
this could be reduced by using a trie/radix tree
void AnagramSort( string[] input )
{
int index = 0;
for ( int i=0; i < input.Length; i++ )
{
if ( IsAnagram(input[i]) )
{
Swap( input, index, i );
index++;
}
}
// Array is now partitioned with all anagrams on the left, all non-anagrams on right.
// If nicer formatting is desired, QuickSort each block of the subArray
// e.g. Array.Sort( input, 0, index - 1 ) and Array.Sort( input, index, input.Length )
}
Read the file.
Store the data in an interval tree.
The interval is stored in seconds and represents the time spent in the room
( so need a function for converting HH:MM:SS to just S )
To compute the # of people in the room at time HH:MM:S
Convert the time to check to S
Get a list of all intervals that overlap the requested time.
the number of people in the room is equal to the size of this list.
IntervalTree provides a good balance between space and time here.
Can also be solved with a hashTable
Key is the time in seconds
Value is the number of people in the room at that time.
Time to populate the table is more expensive as is the memory usage --
but the lookup would be faster.
Actually, you don't need to maintain a count of n.
Just track one number.
When you get a new number; generate a coin-flip (50%/50%).
if heads keep the old number
if tails, overwrite the old number with the new number.
when the sentinel comes up; just return the number.
need to handle the case where the sentinel is first number in the stream.
Repmarkhmitchell6, Analyst at ASAPInfosystemsPvtLtd
At first, tattooing was a hobby kind of thing for me. I didn’t spend too much time in tattoo ...
Repbettylfoster, University dean at Littler's
Hi , I am Betty from the USA , working as Dien in Littler's University for the last three years. Previously ...
Repmarygaustria, Analyst at ADP
I am Mary from Los Angeles, USA. I am working as a Manager in Fragrant Flower Lawn Services company. I ...
Repmakaylamelua, Blockchain Developer at AMD
I am a sound editing and music composer with experience of handling a wide variety of programs.During my free ...
Repggeraldinejrivera, Aghori Mahakal Tantrik at ABC TECH SUPPORT
I am a fashion model, talented in runway turns and photoshoot prep. I Have worked at two displaying organizations and ...
Repamandaben422, Graphics Programmer at Abs india pvt. ltd.
Hi, I am a webmaster from the USA. I think social networks have the power to connect two different people ...
Repjessicajbunting, Aghori Mahakal Tantrik at ABC TECH SUPPORT
Hi I am Jessica, from Houston USA. I am working as a manager in Incredible Universe company. I enjoy additional ...
Repdennahood, Top mobile application Development Company in India at Arista Networks
Je suis Denna, une rédactrice professionnelle avec une expérience complète et de solides atouts en rédaction et en rédaction Web ...
Repkathyrnunez, Area Sales Manager at Advent
I am manager in a Star Bright Investment Group company. I like to solve puzzles for Has excellent problem-solving and ...
RepI am Rasha , C/C++ certified Computer Programmer with expert-level competency in JavaScript, HTML and JSP and more than 6 ...
Repleighpjoyce, job tessio at CapitalIQ
Welcome to my world.I am a safety-conscious HVAC Engineer with experience with mechanical engineering Brampton HVAC design for commercial ...
Repsusanaminick, Research Scientist at CapitalIQ
I am Susan from Dallas, I am working as a Property manager in Kohl's Food Stores company. I love ...
Repmarisamsan7, Cloud Support Associate at ADP
Hi, I am Photoengraver from an CO,USA. I am a girl with a strong desire to travel the world ...
Repmonicaralvarado94, Korean Air Change Flight at Athena Health
I am fond of reading stories then reading articles which are all about a story of a beautiful nature and ...
RepGinaSanchez, Computer Scientist at Autoportal.com
Ginna from New York.Successfully managing a high volume of work assignments without compromising quality to exceed client expectations.Apart ...
- MessyHack June 25, 2014