All Questions
284 questions
0
votes
1
answer
64
views
Problems on Shell Sort (when gap = 1, the algorithm does not work)
I just started to learn algorithms, and found a problem with the Shell Sort algorithm.
I have written 2 versions by C#, but I believe it is easy to understand.
The 1st version, which works well, is as ...
0
votes
2
answers
213
views
Number of overtakes in a race
Im given an input array racers of length N where each racer has it own speed,
(1 <= speed[i] <= 10^8) and starting position. Racers move on a infinitly long track in the same direction.(from ...
-2
votes
3
answers
260
views
In a sorted array of prime numbers arr find index i of the smallest number in arr such that arr[i] divides given number
Consider the following data:
arr = [2,3,5,7,11,13,17,19]
n = 100
Output of the given should be 0 since n % 2 = 0 and arr[0] = 2.
Since array is sorted I want to use that to my advantage and design an ...
2
votes
1
answer
94
views
algorithm: digit substitution based on the same sequence
I can't seem to get a handle on my study assignment.
I'm stuck on the pointer search method. But, I'm thinking about where to change these numbers. I end up with a million if and for.
I have an array ...
2
votes
2
answers
106
views
How to check if array's elements contain specific digit?
I have a task: Implement an FilterByDigit method that obtains an array of integers whose elements contain a given digit. Don't use LINQ. The task definition is given in the XML-comments for this ...
0
votes
4
answers
61
views
Join 2D string array more elegantly
I have a list of argument and value pairs, that I want to join into the format
-arg0=val0 -arg1=val1 ... -argN=valN
The following code works but it feels a bit clumsy and I suspect it can be written ...
0
votes
2
answers
910
views
Remove element not working in leetcode but works in VS
To be brief, I am working on a solution for leetcode question 27, Remove Element. It didn't work when I ran it, the values were completely wrong, but I am really confused as to why it wouldn't, so I ...
0
votes
2
answers
49
views
trying to adjust addition function to a subtraction function
I have this function:
static int[] AddArrays(int[] a, int[] b)
{
Array.Reverse(a);
Array.Reverse(b);
int[] result = new int[Math.Max(a.Length, b....
0
votes
1
answer
53
views
inaccurate results with function to add an array of digits together
so i have this function:
static int[] AddArrays(int[] a, int[] b)
{
int length1 = a.Length;
int length2 = b.Length;
int carry = 0;
int ...
0
votes
2
answers
76
views
Get all split options to k chunks
I need to split an array arr into k chunks where the union of all the chucks is arr and there in no same element in two chunks.
For example for
int[] arr = new int[] {1, 2, 3, 4, 5};
int k = 3;
I ...
0
votes
1
answer
46
views
C# how to find an index of phrase in array of single words
I have an array of words lets say
string[] myWords = { "Arizona", "District", "Court", "is", "located", "at", ".", "District&...
1
vote
2
answers
44
views
finding nth biggest element in multidimensional array
how can I find 5th or 7th, or 15th biggest element in multidimensional array without existing methods (like list.Add)
I will be pleased if you write it in c#
int[,,,] x =new int[100, 20, 35, 200];
......
-1
votes
2
answers
55
views
Optimizing code that calculates sum of largest sequence of decreasing odd ints
I wrote a method that does return sum of decreasing sequence.
For example:
if sequence is 13 9 7 12 13 15, then sum is 29 (13 + 9 + 7).
Now I want to optimize it. Cause the same code is repeating ...
0
votes
3
answers
145
views
I am trying to implement this algorithm to display the name of a person who has the highest salary
The method is returning the name but it's returning the name in the first position of the array: but I want it to return Part Time Employee with highest salary:
Here is what I tried, this is the ...
4
votes
2
answers
370
views
how is this algorithm counting all the unique integers?
below I have an algorithm that counts all the unique integers in an ordered array, but I am not sure how it is doing it using binary search? is anyone able to explain how? thanks.
int unique(int[] a) {...