Gear
BAN USER- 0of 0 votes
AnswersGiven a single core processor and 2 processes executing programs with M and N atomic instructions. How many ways can a scheduler choose to execute them?
- Gear in United States
Example:
M =2 N = 1
Output:
3
{Ma Mb Na}
{Ma Na Mb}
{Na Ma Mb}| Report Duplicate | Flag | PURGE
Software Engineer Algorithm - 0of 0 votes
AnswersA non-empty zero-indexed array A consisting of N numbers is given. The absolute distinct count of this array is the number of distinct absolute values among the elements of the array.
- Gear in United States
For example, consider array A such that
A[0] = -5 A[1] = -3 A[2] = -1
A[3] = 0 A[4] = 3 A[5] = 6
The absolute distinct count of this array is 5, because there are 5 distinct absolute values among the elements of this array, namely 0, 1, 3, 5 and 6.
Write a function
int absDistinct(int A[], int n);
that, given a non-empty zero-indexed array A consisting of N numbers, returns absolute distinct count of array A.
Assume that:
array A is sorted;
N is within the range [1..100,000];
each element of array A is an integer within the range [-2,147,483,648..2,147,483,647].
For example, given array A such that
A[0] = -5 A[1] = -3 A[2] = -1
A[3] = 0 A[4] = 3 A[5] = 6
the function should return 5, as explained above.
?| Report Duplicate | Flag | PURGE
SDE1 - 0of 0 votes
AnswersA magnitude pole of an array A consisting of N integers is an index K such that all elements with smaller indexes have values lower or equal to A[K] and all elements with greater indexes have values greater or equal to A[K], i.e.
- Gear in United States
when and
when K < L < N.
For example, 5 is a magnitude pole of array A such that
A[0]=4, A[1]=2, A[2]=2, A[3]=3, A[4]=1, A[5]=4, A[6]=7, A[7]=8, A[8]=6, A[9]=9.
This array doesn't have any more magnitude poles.
Write a function
int magnitudePole(int A[], int n);
that given an array A consisting of N integers returns any of its magnitude poles. The function should return -1 if array A doesn't have any magnitude poles. Assume that . Assume that each element of the array is a non-negative integer not exceeding 1,000,000.
For example, given array A such that A[0]=4, A[1]=2, A[2]=2, A[3]=3, A[4]=1, A[5]=4, A[6]=7, A[7]=8, A[8]=6, A[9]=9
the function should return 5, as explained above.
?| Report Duplicate | Flag | PURGE
SDE1
I see few issues in this code.
1. m_refCount-- is being updated outside the lock. that mean someone could modify its value while ur in the lock.
2. the lock should be on the min amount of code, what is the point of that check? What are the lock supposed to be locking exactly?
3. return without a unlock will bring all other threads to stop
4. with multiple threads there is a chance u got a reference counter that is negative which is mostly wrong
I have few question what about CC? BCC? why where those skipped? does the substring be unique characters?
- Gear March 05, 2017