ersegun
BAN USER- 2of 2 votes
AnswersA multiset or a bag is a collection of elements that can be repeated. Contrast with a set, where elements cannot be repeated.
- ersegun in Netherlands
Multisets can be intersected just like sets can be intersected.
Input :
A = [0,1,1,2,2,5]
B = [0,1,2,2,2,6]
Output :
A ∩ B = C = [0,1,2,2]
Input :
A = [0,1,1]
B = [0,1,2,3,4,5,6]
Output
A ∩ B = C = [0,1]
Write a function to find the intersection of two integer arrays in that way ?| Report Duplicate | Flag | PURGE
Booking.com Software Developer String Manipulation - 2of 2 votes
Answers"Smart substring"
- ersegun in Netherlands
Write a function that takes maximum 30 characters from a string but without cutting the words.
Full description:
"Featuring stylish rooms and moorings for recreation boats, Room Mate Aitana is a designer hotel built in 2013 on an island in the IJ River in Amsterdam."
First 30 characters:
"Featuring stylish rooms and mo"
Smarter approach (max 30 characters, no words are broken):
"Featuring stylish rooms and"| Report Duplicate | Flag | PURGE
Booking.com Software Developer String Manipulation
C# solution by using Dictionary
private static Dictionary<int, int> CountNumberOfOccurrences(int[] input)
{
Dictionary<int, int> numberOfOccurrences = new Dictionary<int, int>();
foreach(int element in input)
{
if(numberOfOccurrences.ContainsKey(element))
numberOfOccurrences[element] += 1;
else
numberOfOccurrences.Add(element, 1);
}
return numberOfOccurrences;
}
Stack solution in C#.
private const char L_PAREN = '(';
private const char R_PAREN = ')';
private const char L_BRACE = '{';
private const char R_BRACE = '}';
private const char L_BRACKET = '[';
private const char R_BRACKET = ']';
public static bool isBalanced(string s)
{
Stack<char> stack = new Stack<char>();
for (int i = 0; i < s.Length; i++)
{
if (s[i] == L_PAREN)
stack.Push(L_PAREN);
else if (s[i] == L_BRACE)
stack.Push(L_BRACE);
else if (s[i] == L_BRACKET)
stack.Push(L_BRACKET);
else if (s[i] == R_PAREN)
{
if (stack.Count == 0)
return false;
if (stack.Pop() != L_PAREN)
return false;
}
else if (s[i] == R_BRACE)
{
if (stack.Count == 0)
return false;
if (stack.Pop() != L_BRACE)
return false;
}
else if (s[i] == R_BRACKET)
{
if (stack.Count == 0)
return false;
if (stack.Pop() != L_BRACKET)
return false;
}
}
return stack.Count == 0;
}
Repha1904536, Android test engineer at ABC TECH SUPPORT
Hello, I am an Executive recruiter. My role is to fill executive, high-level positions at companies. I have been practicing ...
RepSCREENish employee time tracking software can be used as desktop or mobile app. Once the employee has tracked his working ...
Quick Solution
- ersegun May 10, 2016