dany08
BAN USER
//Amazon Question: You have given an array of integers. The appearance of integers vary (ie some integers appears twice or once or more than once) How would you determine which integers appeared odd number of times ?
//Using Dict C# (Hashmap alternate of Java)
//Time Complexity: O(N)
namespace Noofoccurenceofint
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[] { 1, 1, 1, 2, 2, 5, 8, 9, 5, 9, 10 };
List<int> oddocc = OddTimes(a);
foreach(int n in oddocc)
{
Console.WriteLine(n);
}
}
public static List<int> OddTimes(int[] a)
{
Dictionary<int, int> D = new Dictionary<int, int>();
List<int> oddocc = new List<int>();
for (int i = 0; i < a.Length; i++)
{
if (D.ContainsKey(a[i]))
D[a[i]]++;
else
D[a[i]] = 1;
}
foreach(KeyValuePair<int,int> kvp in D)
{
if (kvp.Value % 2 != 0)
oddocc.Add(kvp.Key);
}
return oddocc;
}
}
C# code:
//Time Complexity: O(n)
public static int Findmissing(int[] A1, int[] A2)
{
Dictionary<int, int> D = new Dictionary<int, int>();
for (int i = 0; i < A1.Length; i++)
{
if (D.ContainsKey(A1[i]))
D[A1[i]]++;
else
D[A1[i]] = 1;
}
for (int i = 0; i < A2.Length; i++)
{
if (D.ContainsKey(A2[i]))
D[A2[i]]++;
else
D[A2[i]] = 1;
}
int missing=0;
foreach (KeyValuePair<int, int> pair in D)
{
if (pair.Value == 1)
{
missing = pair.Key; // Found
break;
}
}
return missing;
}
RepSpent high school summers donating toy monkeys in Minneapolis, MN. At the moment I'm building glue in Edison, NJ ...
RepHello friends my name Neha Nanda from India Chandigarh city. Doing work in SEO line in Softsys company.
Repgeraldgloria02, Android test engineer at Achieve Internet
I am a personal trainer. I design programs and provide nutritional advice and coaching. I wanted to share my knowledge ...
RepTinaaJohn, Cloud Support Associate at AMD
Hi,Everyone.I am an art teacher at Woodson Institute.Foster and encourage critical thinking and analysis about art and ...
Replillymartin, Senior Software Development Engineer at Aristocrat Gaming
Hi everybody! I'm Lilly, a 22 year old girl from Us. Master of economic and financial evaluation of development ...
RepAlmaRJude, Quality Assurance Engineer at Brocade
I am Alma from Livermore USA, I also enjoy reading – my favourite topics being social history, the development and use ...
Replisaramsey773, Blockchain Developer at Adjetter Media Network Pvt Ltd.
I'm a 27 year-old blogger, make-up junkie and follower of Christ.I love all things that bring happiness. My ...
RepNatalieLutz, Applications Developer at Absolute Softech Ltd
Pitch trending story topics and continually look for ways to push breaking and/or viral stories forward with new angles ...
Repjanicepdaniels1, Backend Developer at Accenture
I decided to become an entrepreneur and work for myself because I wasn't making the money I wanted to ...
RepMy name Madhu Nanda from Himachal pardesh. I am a writter in English lectractrue.
Repcharlesgwitt47, Animator at ASU
By Profession, I am a Automotive service technician in Kennewick USA. My strong interest is in yoga, My yogic journey ...
Reprachelwrosa1, Computer Scientist at ABC TECH SUPPORT
Hello, I am Rachel and I live in Charleston, USA. I am working as a data entry clerk who is ...
RepI am an energetic sales professional with a track record of consistently increasing sales revenue in a competitive market. Contract ...
Firstly, the question is to find the first common factor not the least common factor. I've used a simple recursive approach:
Given p and q nodes.
Check If p.parent == q.parent
- if yes, return p
- if no, traverse p and q upwards. (i.e p.parent, q.parent), until we find a equal nodes.
- dany08 June 05, 2016