All Questions
Tagged with programming-challenge performance
629 questions
0
votes
2
answers
1k
views
(Leetcode) Brick wall
I would like to know whether I could make my solution to this Leetcode challenge much faster.
There is a brick wall in front of you. The wall is rectangular and has
several rows of bricks. The ...
7
votes
2
answers
2k
views
Arranging numbers in a circle such that the sums of neighbors and sums of diametric opposites are prime
I need to create a circle with numbers from 1 to n , however it is necessary to respect some rules:
All numbers from 1 to n are used in the circle only once.
The sum of two consecutive numbers ...
1
vote
1
answer
269
views
(Leetcode) Freedom Trail
I would like to know whether I could make my solution to this challenge shorter and more efficient. Below is the description of the challenge (this is a Leetcode problem) -
In the video game ...
3
votes
1
answer
435
views
(Leetcode) Perfect Rectangle
This is a Leetcode problem -
Given \$N\$ axis-aligned rectangles where \$N\$ \$>\$ 0, determine if
they all together form an exact cover of a rectangular ...
4
votes
1
answer
633
views
The Dungeon game
This is a Leetcode problem -
The demons had captured the princess (P) and imprisoned her in the
bottom-right corner of a dungeon. The dungeon consists of M x N rooms
laid out in a 2D grid. Our ...
6
votes
2
answers
117
views
Program for activity selection exceeds time limit
I've been trying to solve this problem for some while and the solution I have come up with exceeds the lime limit by 1-3 ms and 2 out of 10 tests get a memory issue error. Why is that? This is the ...
4
votes
2
answers
946
views
(Leetcode) Escape a large maze
This is a Leetcode problem -
In a 1 million by 1 million grid, the coordinates of each grid square
are (x, y) with \$0\$ \$<=\$ ...
2
votes
0
answers
2k
views
(Leetcode) Longest consecutive sequence in Python
This is a Leetcode problem -
Given an unsorted array of integers, find the length of the longest
consecutive elements' sequence.
Your algorithm should run in \$O(n)\$ complexity.
...
10
votes
2
answers
3k
views
Project Euler #7 10001st prime in C++
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can
see that the 6th prime is 13.
What is the 10 001st prime number?
How can I optimize this code?
...
2
votes
0
answers
371
views
Bursting Balloons
This is a Leetcode problem -
Given n balloons, indexed from 0 to n-1. Each balloon is ...
5
votes
2
answers
1k
views
(Leetcode) Minesweeper game
This is a Leetcode problem -
Let's play the Minesweeper game
(Wikipedia,
online game)!
You are given a 2D char matrix representing the game board. 'M'
represents an unrevealed mine, 'E' ...
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 ...
2
votes
1
answer
383
views
(Leetcode) K-similar strings in Python
This is a Leetcode problem -
Strings A and B are K-similar (for some non-negative integer
...
5
votes
0
answers
89
views
Finding duplicates in an array using C [closed]
I came across a problem on LeetCode.
There is an input array of integers. I need to find out if there any repeating integers, then return true else false.
So, I tried using a hashtable library ...
4
votes
1
answer
2k
views
(Leetcode) 24 game in Python
This is a Leetcode problem -
You have 4 cards each containing a number from 1 to 9. You need to
judge whether they could be ...
1
vote
2
answers
884
views
Strong password checker in Python
This is a Leetcode problem -
A password is considered strong if below conditions are all met -
1. It has at least 6 characters and at most 20 characters.
2. It must contain at least one ...
4
votes
1
answer
2k
views
Find all concatenated words in a given list of words
This is a Leetcode problem -
Given a list of words (without duplicates), write a program that
returns all concatenated words in the given list of words.
A concatenated word is defined as a ...
0
votes
2
answers
1k
views
Split an array into m subarrays such that the largest subarray sum is minimized
This is a Leetcode problem -
Given an array which consists of non-negative integers and an integer
m, you can split the array into ...
7
votes
2
answers
12k
views
Python program to solve the "skyline problem"
This is a Leetcode problem -
A city's skyline is the outer contour of the silhouette formed by all
the buildings in that city when viewed from a distance. Now suppose
you are given the ...
1
vote
1
answer
2k
views
Python program to remove invalid parentheses
This is a Leetcode problem -
Remove the minimum number of invalid parentheses in order to make the
input string valid. Return all possible results.
Note -
The input string may contain ...
1
vote
1
answer
485
views
Python program for Word Search II
This is a Leetcode problem -
Given a 2D board and a list of words from the dictionary, find all
words in the board.
Each word must be constructed from letters of a sequentially adjacent
...
2
votes
2
answers
577
views
Python program for Jump game II
This is a Leetcode problem:
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length ...
-3
votes
3
answers
1k
views
Python program to find the first missing positive integer in a list
This is a Leetcode problem:
Given an unsorted integer array, find the smallest missing positive
integer.
Note:
Your algorithm should run in O(n) time and uses constant extra space.
...
0
votes
1
answer
380
views
Python program to find the substring with concatenation of all words
This is a Leetcode problem:
You are given a string, S, and a list of words, L that are all of the same lengths. Find all starting indices of substring(s) in S that is a concatenation of each word ...
5
votes
1
answer
62
views
Find amounts that cannot be composed using the given coins
I need to make a program that receives a set of currencies and tests which values between 1 and 10,000 units can not be produced with these currencies.
The program must have 2 input data:
The ...
1
vote
1
answer
1k
views
Writing billions of lines to text file in java [closed]
I'm trying to write billions of strings lines to a file, it works for up to 40 million lines, but it's throwing out "java.nio.BufferOverflowException" error for 400 million lines. I also think my ...
5
votes
2
answers
531
views
Pascal's Triangle Java (performance)
I need to get some information about the Pascal Triangle.
What is a pascal triangle ?
It is a triangle of integers with 1 at the top and at the sides. Any number inside is equal to the sum of the ...
5
votes
1
answer
2k
views
Project Euler 76: Counting summations
Project Euler Problem 76 asks:
How many different ways can one hundred be written as a sum of at least two positive integers?
My code is correct but just works slowly.
...
1
vote
2
answers
150
views
Segmented Sieve Spoj
I tried(trying...) to solve the SPOJ prime number problem PRIME1 so i learned and implemented Segmented Sieve correctly but this program works in time for 10^8 but getting Time limit exceeded (TLE) ...
4
votes
1
answer
1k
views
5
votes
1
answer
1k
views
Google Kick Start Practice Round 2019 - Mural
My code exceeds the time limit on the second test set. A suggestion/hint of a better algorithm would be appreciated.
Problem
Thanh wants to paint a wonderful mural on a wall that is N ...
2
votes
1
answer
244
views
Leetcode: Detecting duplicate elements in an array within a k-element window
Upon solving the problem 'contain duplicates` in leetcode:
Given an array of integers and an integer k , find out whether there are two distinct indices i and j in the array such that nums[i] = ...
4
votes
1
answer
4k
views
4 solutions to leetcode 202. Happy Number have almost same performance
I am working on an easy math question Happy number Happy Number - LeetCode
Happy Number
Write an algorithm to determine if a number is "happy".
A happy number is a number defined by ...
2
votes
1
answer
80
views
Kahn's algorithms to arrange CouseSchedule
I wrote a solution to Course Schedule II - LeetCode
There are a total of n courses you have to take, labeled from 0 to n-1.
...
5
votes
2
answers
485
views
Programming Challenge from Kattis: Watchdog
I've tried to solve the kattis-challenge called Watchdog. My code works just fine, but it was too slow on the last test. I'm wondering if anyone sees any big algorithmic performance issues.
A short ...
3
votes
1
answer
91
views
(Follow-up) Project Euler #11 Largest Product in a Grid | Cache-optimized + sliding window (C++14)
Original code review: Project Euler #11 Largest Product in a Grid | Cache-optimized + sliding window (C++14)
Source: HackerRank & ProjectEuler.net
Problem: Largest Product in a Grid
In the 20×...
2
votes
2
answers
148
views
Project Euler #11 Largest Product in a Grid | Cache-optimized + sliding window (C++14)
Source: HackerRank & ProjectEuler.net
Problem: Largest Product in a Grid
In the 20×20 grid below, four numbers along a diagonal line have been marked in red.
...
2
votes
1
answer
1k
views
Splice-merge two sorted lists in Python
I tried to solve a merge two sorted list problem in leetcodes:
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two ...
10
votes
1
answer
2k
views
Google Kickstart Round A 2019 - Training
Problem: Training
As the football coach at your local school, you have been tasked with
picking a team of exactly P students to represent your school. There
are N students for you to pick ...
1
vote
1
answer
368
views
In an set of integers, find three elements summing to zero (3-sum, leetcode variant)
I use a dummy solution to solve the leetcode 3Sum problem.
I employ the set data type to handle duplicates, then transform back to list.
Given an array nums ...
4
votes
0
answers
105
views
Writing Go object code that respects Go guidelines
I'm learning Go and I wrote this for a programming challenge. It is working (building and running) but I feel the code is not what Go code should be:
Am I using the ...
2
votes
2
answers
4k
views
Determine which sentences contain the set of phrases
I am trying to solve this HackerRank challenge which asks to write a function that prints the indexes of all sentences which contain the query words. For example, if the inputs to the function are:
<...
4
votes
1
answer
2k
views
Hackerrank All Women's Codesprint 2019: Name the Product
Link: https://www.hackerrank.com/contests/hackerrank-all-womens-codesprint-2019/challenges/name-the-product/
Problem
You are contesting to name a new product in your company given the ...
1
vote
2
answers
110
views
(Brilliant.org) Arrays Intermediate 3: Contiguous Knapsack
Problem
Given an array and a number \$t\$, write a function that determines if there exists a contiguous sub-array whose sum is \$t\$.
Source (Note that the URL may not link to the exact problem as ...
3
votes
1
answer
1k
views
(Codewars) Linked Lists - Remove Duplicates
Kata: https://www.codewars.com/kata/linked-lists-remove-duplicates/train/python
Description
Write a RemoveDuplicates() function which takes a list sorted in increasing order and deletes any ...
3
votes
2
answers
153
views
Find how many inequalities can be simultaneously satisfied
Inequality
Given n inequalities about X, how many of them can hold at the same time at most?
The inequalities are in the following forms:
X < C
X <= C
X = C
X > C
X >= C
input
First ...
0
votes
1
answer
312
views
Finding the longest Collatz sequence using Go, concurrently
I am working through this problem on project euler.
Basic purpose of the code:
...
7
votes
2
answers
3k
views
Deepest pit of an array
Following is based on a problem description from a Codility test, as a task in an interview.
DeepestPit - problem description
A non-empty zero-indexed array B ...
8
votes
2
answers
457
views
(Codewars Kata) Memoised Log Cutting
(I am not sure of the official CS name for the problem in question, so I just gave it the name of the kata).
Problem
CLEAR CUTTER'S NEEDS YOUR HELP!
The logging company Clear Cutter's ...
5
votes
1
answer
95
views
Linear regression on points specified by the user in a GUI
Here's my take on the Linear Regression exercise from John Zelle's Python book.
Open a window, let the user click on as many points as they want. Upon pressing the "Done" button the regression line ...