All Questions
62 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 ...
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 ...
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 ...
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 ...
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
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
...
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....
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 ...
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 ...
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
...
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\$ ...
4
votes
1
answer
279
views
LeetCode: Symmetric Tree C#
https://leetcode.com/explore/interview/card/top-interview-questions-easy/94/trees/627
Given a binary tree, check whether it is a mirror of itself (ie,
symmetric around its center).
For ...
6
votes
3
answers
2k
views
LeetCode: Group Anagrams C#
LeetCode: Group Anagrams C#
Given an array of strings, group anagrams together.
...
2
votes
2
answers
3k
views
Run length encoding in C#
This is the original question:
https://www.geeksforgeeks.org/run-length-encoding/
Given an input string, write a function that returns the Run Length
Encoded string for the input string. For ...
3
votes
1
answer
200
views
LeetCode: Transpose Matrix C#
Please review performance
https://leetcode.com/problems/transpose-matrix/
Given a matrix A, return the transpose of A.
The transpose of a matrix is the matrix flipped over it's main
diagonal, ...
3
votes
2
answers
250
views
LeetCode: Leaf-similar trees C#
Please comment about performance
https://leetcode.com/problems/leaf-similar-trees/
Consider all the leaves of a binary tree. From left to right order,
the values of those leaves form a leaf ...
5
votes
1
answer
924
views
Count pairs in list of integers such that their addition is equal to the input value
Given a List<int>, the problem I am trying to solve is:
Find the number of unique pairs in List<int> such that their ...
1
vote
2
answers
616
views
Faster code for leetcode reverse int
This is my solution for the leetcode reverse int question:
Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
Input: 123 Output: 321 Example 2:
Input: -123 ...
8
votes
4
answers
4k
views
Reversing a string - two approaches
Test Case:
Input- "I'm hungry!"
Output- "!yrgnuh m'I"
Approach 1: In this approach, I used a empty string and bind it with the input string reversely.
...
4
votes
1
answer
100
views
Sport Cards Task
The task:
You will receive several input lines in one of the following formats:
"{card} - {sport} - {price}"
...
3
votes
2
answers
140
views
Data Transfer Task
The task:
You will be given several lines of messages containing data. You have
to check for the validity of the lines. A valid line should be in the
format: ...
2
votes
2
answers
8k
views
Hacker Rank: Counting names with prefix matches using a trie
Practicing hacker rank questions and would love some feedback on how I could perform optimizations on a Trie.
This code will add a bunch of names into a trie and then when asked will turn how many ...
2
votes
1
answer
158
views
Project Euler: Find 10.001st prime
I have just started learning C# and decided to do some problems from Project Euler. I wrote a code to find 10 001st prime and I thought it would be cool optimize it to make it as fast as possible. How ...
6
votes
4
answers
615
views
Pascal Triangle calculation with BigIntegers
On a well known programming challenges website(CW) there is a Kyu2 eggs height problem that can be solved utilizing a variation of Pascals Triangles properties.
The problem asks to solve ...
0
votes
1
answer
176
views
Pascal Triangle c# code space complexity
can you give me your impression of my implementation of Pascal triangle problem?
I'm especially interested in space complexity evaluation
thank you all!
...
3
votes
3
answers
2k
views
Interleaving two strings
The challenge:
From: URI Online Judge
Implement a program Combiner that takes two Strings as parameters and combines them, alternating letters, starting with the first letter of the first String, ...
3
votes
1
answer
128
views
Longest Absolute File Path in Leetcode
I solved the Longest Absolute File Path challenge from Leetcode.
The question is
Suppose we abstract our file system by a string in the following
manner:
The string ...
8
votes
3
answers
2k
views
Leetcode 125. Valid Palindrome (better performance?)
Problem statement
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama" is a ...
4
votes
1
answer
1k
views
Hackerrank: Prefix neighbors
Problem statement
Mark has a dictionary, S, containing n distinct strings. He defines the benefit value of a string
as the ...
5
votes
4
answers
1k
views
Optimizing Bingo Caller Method
I am dong a competitive programming problem I have passed all the tests.
but my program times out. I need help optimizing my code so it can run faster.
Task:
Finish method: ...
3
votes
0
answers
787
views
Hackerrank: Sherlock and anagram (optimal time complexity)
Problem statement
Given a string \$S\$, find the number of "unordered anagrammatic pairs" of substrings.
Input Format
First line contains \$T\$, the number of testcases. Each testcase ...
7
votes
3
answers
8k
views
Find K biggest numbers in the array
I was trying to implement method number 2, from this article.
Method 2 (Use temporary array) K largest elements from arr[0..n-1]
Store the first k elements in a temporary array temp[0..k-1]....
6
votes
3
answers
1k
views
Project Euler #47: Distinct primes factors
I have solved Project Euler's problem number 47, which reads:
The first two consecutive numbers to have two distinct prime factors
are:
14 = 2 × 7
15 = 3 × 5
The first three ...
5
votes
3
answers
3k
views
HackerRank woman codesprint: minimum cost
Lauren has a chart of projected prices for a house over the next n
years, where the price of the house in the i-th year is <...
6
votes
1
answer
848
views
Isomorphic strings in LeetCode
I solved this problem:
Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to
get t.
All occurrences of a ...
8
votes
3
answers
1k
views
Word Pattern challenge in LeetCode
I solved this problem from LeetCode:
Given a pattern and a string str, find if str follows the same
pattern.
Here follow means a full match, such that there is a bijection between
a letter ...
5
votes
5
answers
2k
views
Project Euler #3 in C# - largest prime factor
I just started doing the Project Euler challenges and right now I'm on Challenge #3 - The largest prime factor of 600851475143.
I wrote some code and tried to optimize it based on some other Stack ...
30
votes
6
answers
4k
views
DailyProgrammer 284: Wandering Fingers
Description
Software like Swype and SwiftKey lets smartphone users enter text by dragging their finger over the on-screen keyboard, rather than tapping on each letter.
You'll be given ...
0
votes
1
answer
1k
views
Project Euler #50 Consecutive prime sum
I'm having trouble optimising the project euler #50 exercise, it runs for around 30-35 seconds, which is terrible performance.
The prime 41, can be written as the sum of six consecutive primes:
...
24
votes
12
answers
4k
views
Project Euler 8: Maximum product of 13 adjacent digits
Problem 8 on Project Euler which asks
Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the product?
This is my solution in Visual C#.
...
1
vote
3
answers
518
views
Project Euler #43
I'm having trouble optimizing the Project Euler problem #43 :
The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a ...
3
votes
2
answers
495
views
Project Euler Problem #41
I recently finished the project Euler problem # 41 :
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital ...
2
votes
3
answers
599
views
Project Euler #34 Digit factorials
I'm having trouble improving the performance of the solution to the Project Euler problem #34
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
Find the sum of all numbers which are ...
5
votes
2
answers
673
views
Project Euler #23 Non-abundant sums
I'm having trouble optimizing the Project Euler problem number 23 :
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the ...
33
votes
7
answers
6k
views
Project Euler #7 10001st prime
I decided to start working on the Euler project exercises. I'm doing fine for now but the seventh problem is running quite slow and I can't think of anything to make it work faster. It takes around ...
4
votes
2
answers
728
views
Computing the divisor sum in bulk without division, multiplication or factorisation (SPOJ DIVSUM)
SPOJ problem #0074 DIVSUM - Divisor Summation requires computing the sums of proper divisors in bulk (200000 test cases, time limit 3 seconds):
Given a natural number n (1 <= n <= 500000), ...
3
votes
2
answers
616
views
Project Euler 25 - x-digit Fibonacci Number
I have solved the Problem 25 of the Euler Project:
The Fibonacci sequence is defined by the recurrence relation:
\$\qquad F_n = F_{n−1} + F_{n−2}\$, where \$F_1 = 1\$ and \$F_2 = 1\$.
...