All Questions
165 questions
1
vote
1
answer
107
views
Find Method Implementation for Multidimensional Array in C#
I found that Array.Find(T[], Predicate) Method is only support one dimensional array. I am trying to generalize it to multi-dimensional array in this post.
The experimental implementation
The ...
1
vote
1
answer
112
views
"stray" point correction in 2D array
I have a code which does the following:
For each value v in a 2D array, look at neighboring positions - how far to look is specified by distThreshold. If the count ...
3
votes
2
answers
122
views
Quickselect algorithm implementation and its time-complexity
I wrote this code to find kth smallest element in the array by renowned algorithm quickselect. Here is the link where you can see the working code.
What points are there to be improved? Could you ...
1
vote
1
answer
184
views
swap two different length group of variable in array
The code below swaps two different-length groups of variables of the same array in the same array.
Is there any other method to achieve this that is less heavy or less redundant?
...
1
vote
1
answer
267
views
C# Get All Diagonals Jagged Array
How can I improve this?
The idea is to store every left to right diagonals in a list
Not looking for a more efficient algorithm instead something readable, LINQ perhaps?
input:
3, 1
2, 5, 7
1, 5, 8, 3,...
3
votes
2
answers
406
views
Calculate sum of largest sequence of decreasing odd ints
I wrote a method that finds the maximum sum of consecutive decreasing sequence of odd integers.
For example: if sequence is 13 9 7 12 13 15 13, then sum is 29 (13 + 9 + 7).
I don't think it's as good ...
0
votes
1
answer
1k
views
How to split a file with multiple lines into fractional array elements?
I have a file with content:
4;10;3;6;10
6;9;1;3;5
3;2;1;1;2,65
I need to split each line of the file into an fractional (double) array with elements as these ...
0
votes
1
answer
132
views
Distribute items over array in order to minimize the difference between min and max array values
I came across this problem in a programming challenge a few days ago. I came up with the implementation below, however it resulted in a "time limit exceeded" failure for a few of the test ...
1
vote
1
answer
3k
views
Best way to convert the string with Byte sequence to Byte Array
We had a string with byte array (hexadecimal) sequence, like: ...
0
votes
2
answers
485
views
Time complexity of generating Pascal's triangle
This is LeetCode question 118 Pascal's triangle.
Given an integer numRows, return the first numRows of Pascal's triangle.
There is an example.
Input: numRows = 5
Output: [[1],[1,1],[1,2,1],[1,3,3,1]...
3
votes
1
answer
369
views
Grouping anagrams together from a string array
I wrote this code in c#. It is a question from LeetCode, number 49. Given an array of strings, group the anagrams.
The examples it gives are:
["eat","tea","tan","...
4
votes
4
answers
200
views
Better way to minimize array elements
I would like the array elements to minimize by preserving their orders. For example:
3,7,9,7 is given 1,2,3,2 is yielded
...
2
votes
2
answers
112
views
Print Binary coded decimal Numbering of a given input number
Example 1
input:3
output:0011
Example 2
input : 15
output: 1111
in the below example code 15 is input.
I have taken 8 4 2 1 as array for Binary coded decimal numbering
this code is working as ...
3
votes
3
answers
1k
views
Printing rotations of an array 7 times
Loop through a given array 7 times and print the following output:
int[] arr = { 9, 2, 7, 4, 6, 1, 3 };
...
5
votes
1
answer
1k
views
More efficient way to create an ASCII maze using box characters
I've written a C# program to generate a random maze, and then draw that maze in the Console mode using box-drawing characters, e.g. ─ │ ┌ ┐ ┬ ┼ etc. It works fine, as below, but I'm not convinced that ...