All Questions
Tagged with programming-challenge c#
296 questions
3
votes
1
answer
106
views
Coding puzzle - Passing year books
Question:
There are n students, numbered from 1 to n, each with their own
yearbook. They would like to pass their yearbooks around and get them
signed by other students.
You're given a list of n ...
2
votes
1
answer
156
views
Advent of Code 2023 Day 2 in C#
To paraphrase the puzzle, Santa takes a walk with an Elf, and they play a game involving a bag of colorful cubes. In each game, there is an unknown number of each colored cubes in the bag, and the Elf ...
0
votes
2
answers
446
views
LeetCode: C# fibonacci number iterative solution
https://leetcode.com/problems/fibonacci-number/
The Fibonacci numbers, commonly denoted F(n) form a sequence, called
the Fibonacci sequence, such that each number is the sum of the two
preceding ones,...
0
votes
1
answer
126
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
2k
views
HackerRank CountingSort 1 in C#
Comparison Sorting
Quicksort usually has a running time of n x log(n), but is there an algorithm that can sort even faster? In general, this is not possible. Most sorting algorithms are comparison ...
4
votes
1
answer
840
views
Kattis challenge, processing string with special characters and conditions
I'm new to programming challenges and I'm attempting the following Kattis challenge Sim.
This problem is an extension of another Kattis problem - backspace. In that problem, every time we see a ...
4
votes
1
answer
906
views
Determine whether an array contains duplicate values
My solution for the leet code problem to search an array of ints for duplicate values and return a boolean seems quite efficient (< 90% of submissions runtime). However, I am currently reviewing ...
1
vote
2
answers
123
views
I want reduce the time complexity for this ladder problem to find the minimum ladders required
I was trying to attempt below given challenge. I tried multiple ways to solve the problem but none of them were good enough to pass the time limit. Please advise if you have any idea to improve on ...
0
votes
1
answer
264
views
LeetCode: Sort The Matrix Diagonally C#
https://leetcode.com/problems/sort-the-matrix-diagonally/
A matrix diagonal is a diagonal line of cells starting from some cell
in either the topmost row or leftmost column and going in the
bottom-...
4
votes
2
answers
270
views
Minimum number of copies of an application a company needs to purchase
Some applications from vendors are allowed to be installed on multiple computers per user with specific
restrictions. In our scenario, each copy of the application (ID 374) allows the user to install ...
3
votes
0
answers
311
views
LeetCode: Stone Game C#
https://leetcode.com/problems/stone-game/
Alex and Lee play a game with piles of stones. There are an even
number of piles arranged in a row, and each pile has a positive
integer number of stones ...
2
votes
1
answer
2k
views
DateTime range splitting algorithm
I have the algorithm which splits DateTime range into multiple ranges based on night time range.
For example:
Night start: 22:00, Night end: 06:00
Start time: 2020-10-26 21:00:00 End time: 2020-10-27 ...
5
votes
4
answers
2k
views
C#: Repeated String
From HackerRank "Repeated String" challenge:
Lilah has a string, \$s\$, of lowercase English letters that she repeated
infinitely many times.
Given an integer, \$n\$, find and print the ...
4
votes
1
answer
174
views
LeetCode: Find And Replace in String C#
It took me a while to solve this question and there are corner cases i missed hence the 4 unit tests.
please review for performance. and if you can treat this as a review for a 45 mins programming ...
7
votes
2
answers
176
views
LeetCode: my calender 2 C#
https://leetcode.com/problems/my-calendar-ii/
Implement a MyCalendarTwo class to store your events. A new event can
be added if adding the event will not cause a triple booking.
Your class will have ...
-2
votes
2
answers
209
views
1
vote
0
answers
302
views
LeetCode:MineSweeper C#
https://leetcode.com/problems/minesweeper/
please review for performance. I really don't like the implementation I made for GetNumberOfMines() function, but within the time limits i did this. it is ...
3
votes
2
answers
349
views
LeetCode: Deepest Leaves Sum C#
Given a binary tree, return the sum of values of its deepest leaves.
Constraints:
The number of nodes in the tree is between 1 and 10^4. The value of
nodes is between 1 and 100.
...
1
vote
1
answer
221
views
LeetCode: FloodFill C#
https://leetcode.com/problems/flood-fill/
An image is represented by a 2-D array of integers, each integer
representing the pixel value of the image (from 0 to 65535).
Given a coordinate (sr,...
2
votes
1
answer
72
views
LeetCode: Increasing Order Search Tree C#
https://leetcode.com/problems/increasing-order-search-tree/
Please review for performance
Given a binary search tree, rearrange the tree in in-order so that the
leftmost node in the tree is now ...
-3
votes
1
answer
107
views
Does my code follow good clean code conventions? [closed]
Here is a class that I have implemented in order to sort rows of parameters in the form of an array of strings.
...
1
vote
1
answer
293
views
LeetCode: Divide Array in Sets of K Consecutive Numbers C#
https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/
Given an array of integers nums and a positive integer k, find whether
it's possible to divide this array into sets of ...
3
votes
1
answer
121
views
LeetCode: Network Delay Time Bellman Ford C#
https://leetcode.com/problems/network-delay-time/
There are N network nodes, labelled 1 to N.
Given times, a list of travel times as directed edges times[i] = (u,
v, w), where u is the ...
3
votes
1
answer
970
views
LeetCode: Sliding Window Median C#
https://leetcode.com/problems/sliding-window-median/
Median is the middle value in an ordered integer list. If the size of
the list is even, there is no middle value. So the median is the mean
...
2
votes
1
answer
1k
views
LeetCode: Sum of Two Integers C#
https://leetcode.com/problems/sum-of-two-integers/
Calculate the sum of two integers a and b, but you are not allowed to
use the operator + and -.
Example 1:
Input: a = 1, b = 2 Output: ...
3
votes
4
answers
3k
views
LeetCode: Number of steps to reduce a number to zero C#
https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/
Given a non-negative integer num, return the number of steps to reduce
it to zero. If the current number is even, you ...
2
votes
1
answer
181
views
LeetCode: Trapping Rain Water DP C#
Please review for performance and C# style.
I already solved this question in 1 way.
LeetCode: trapping rain water C#
I tried also the dynamic programming approch
https://leetcode.com/problems/...
2
votes
1
answer
336
views
LeetCode: Network Delay Time Dijkstra's Algorithm C#
https://leetcode.com/problems/network-delay-time/
There are N network nodes, labelled 1 to N.
Given times, a list of travel times as directed edges times[i] = (u,
v, w), where u is the ...
2
votes
1
answer
107
views
Propagation in grid
Can I do it with a lower Big O / better code? How can I improve this solution?
Task:
Let's assume we have a array like this:
1 0 0 1 0
0 0 0 0 0
0 0 0 1 0
0 0 0 0 0
1 0 0 0 0
...
4
votes
1
answer
535
views
LeetCode: Binary Tree Level Order Traversal C#
Please review for performance. and also naming convention
https://leetcode.com/problems/binary-tree-level-order-traversal/
Given a binary tree, return the level order traversal of its nodes'
...
4
votes
3
answers
579
views
LeetCode: Validate Binary Search Tree C#
I was struggling with this question for many times,
and I have solved it every time, because I understand the concept.
but I can never get to a good concise solution which is easy to follow.
In a ...
6
votes
1
answer
264
views
Counting Direct and Indirect Orbits and Counting Distance of Orbits - Advent of Code Day 6
I recently solved Advent of Code 2019 Day 6 in C#.
Part 1:
You've landed at the Universal Orbit Map facility on Mercury. Because
navigation in space often involves transferring between orbits, ...
6
votes
2
answers
3k
views
Find the largest sum of any slice inside an array
This is the 26th exercise I solved from Codility. It scores 100%. I think I improved a lot since I started with this lessons, around 2 months ago, but still every post I made had things to be improved....
8
votes
1
answer
2k
views
Mars Rover Challenge in C#
This is my code for the Mars Rover Challenge, would be nice to get some opinions on it. More details about what the Mars Rover challenge is can be found here:
https://code.google.com/archive/p/...
3
votes
1
answer
693
views
Count the number of leaders in both sides (slices) of an array in C#. Codility EquiLeaders task
EquiLeader
A non-empty array A consisting of N integers is given.
The leader of this array is the value that occurs in more than half of
the elements of A.
An equi leader is an ...
8
votes
1
answer
835
views
FizzBuzz in Csharp
For my first CodeReview, I would like to present my FizzBuzz solution in C#. My design has all of the rule logic about when to display what in separate classes through an interface. This design should ...
1
vote
1
answer
3k
views
Codility's stonewall 100% solution - different paths such as if,else if,etc, do the same thing
Here is the task description for the codility's stonewall problem. I would like to get a feedback on my code, and I specify at the bottom what the title states. (I had to make the figure by hand, ...
3
votes
0
answers
230
views
Longest palindrome code in C# takes time out on LeetCode
I like to request a review of the code below, which is my attempt at answering the question here on LeetCode site. The code passes 43 tests, but it times out on the next one. I copied and ran the test ...
3
votes
2
answers
341
views
LeetCode: Shortest Common Supersequence C#
https://leetcode.com/problems/shortest-common-supersequence/
Given two strings str1 and str2, return the shortest string that has
both str1 and str2 as subsequences. If multiple answers exist, ...
2
votes
1
answer
822
views
LeetCode: Greatest Common Divisor of Strings C#
https://leetcode.com/problems/greatest-common-divisor-of-strings/
For strings S and T, we say "T divides S" if and only if S = T + ... +
T (T concatenated with itself 1 or more times)
...
3
votes
2
answers
413
views
LeetCode: Diameter of Binary Tree
https://leetcode.com/problems/diameter-of-binary-tree/
Given a binary tree, you need to compute the length of the diameter of
the tree. The diameter of a binary tree is the length of the longest
...
7
votes
2
answers
381
views
LeetCode: Burst Balloons C#
https://leetcode.com/problems/burst-balloons/
Given n balloons, indexed from 0 to n-1, ...
2
votes
1
answer
1k
views
Codility's GenomicRangeQuery solution in C#
I've been learning C# for a few months now, and I've done some basic things in java last year. I made a solution for the problem the title states, this is the task description.
Task description
...
3
votes
2
answers
148
views
Q: Project Euler #1 - C#
Good day, it's my first time doing something like this so I wanted to solve some of the challenges on project Euler, however I reached a block on my code, even before I submitted I was aware that I ...
4
votes
1
answer
695
views
LeetCode: Rotting Oranges in C#
https://leetcode.com/problems/rotting-oranges/
Please review for coding style in 40 minutes job interview.
In a given grid, each cell can have one of three values:
the value 0 representing an ...
1
vote
2
answers
234
views
LeetCode: Spiral Matrix II C#
https://leetcode.com/problems/spiral-matrix-ii/
Please review for performance, how can this code run faster
Given a positive integer n, generate a square matrix filled with
elements from 1 to n^2 ...
7
votes
2
answers
1k
views
Letter Combinations of a phone number using a Dictionary
Problem statement (online source)
Given a digit string, return all possible letter combinations that the
number could represent.
A mapping of digit to letters (just like on the telephone ...
2
votes
1
answer
778
views
Codility's count passing cars in opposite directions in C#
I programmed a few things in java and now I'm learning C#. I've been doing exercises from Codility.
The first 3 or 4 were very difficult to me but now I guess I've got the hang of it. This site ...
5
votes
2
answers
2k
views
MaxCounters solution in C# from Codility
I programmed a little in java a while back, and now I'm learning C#.This is the first exercise of "medium" or "respectable" difficulty according to Codility, so I'm pretty pleased of finding out that ...
2
votes
1
answer
167
views
LeetCode: Queue Reconstruction by Height C#
https://leetcode.com/problems/queue-reconstruction-by-height/
Suppose you have a random list of people standing in a queue. Each
person is described by a pair of integers \$(h, k)\$, where \$h\$ ...