Questions tagged [programming-challenge]

Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.

Filter by
Sorted by
Tagged with
3
votes
2answers
97 views

Sum of primes up to 2 million using the Sieve of Eratosthenes

I've solved question 10 on Project Euler using the Sieve of Eratosthenes, what can I do to optimize my code? ...
4
votes
1answer
36 views

Convert an in-ordered and pre-ordered array to a BST

I am working on a Daily Coding Challenge to print the BST if given an in-ordered and pre-ordered array. Below is my code in JavaScript ES6. Please can you review it. This is my first fully-featured ...
4
votes
1answer
133 views

Policemen catch thieves

Given an array of size n that has the following specifications: Each element in the array contains either a policeman or a thief. Each policeman can catch only one thief. A policeman ...
1
vote
0answers
73 views

Shortest way to form a string out of a subsequence of a string

The task is taken from LeetCode - From any string, we can form a subsequence of that string by deleting some number of characters (possibly no deletions). Given two strings source and target,...
3
votes
1answer
48 views

Collect maximum fruits in two baskets of at most 2 types of fruits

The task is taken from LeetCode In a row of trees, the i-th tree produces fruit with type tree[i]. You start at any tree of your choice, then repeatedly ...
4
votes
0answers
49 views

SQLite In-memory Database That Inserts Data Read From a CSV File

I wrote this program to make a simple in-memory database using SQLite and JDBC. Requirements I was trying to accomplish are below. It should consume a CSV file, parse the data, and insert it into the ...
3
votes
2answers
135 views

Optimal burger-eating challenge

Little history to give context to the problem: The Krusty-Burgers Homer Simpson is a smart guy who likes to eat Krusty-Burgers, and it takes m minutes for Homer ...
6
votes
4answers
3k views

“What is the maximum that Player 1 can win?”

This is a question that I encountered in one of the competitive coding tests. The question goes as follows: A 2-player game is being played. There is a single pile of stones. Every stone has an ...
1
vote
1answer
60 views

Rotate matrix clockWise and counter clockWise

This code is a mix of the same question one time rotating to the right and one time to the left. I tried to simplify the code since I'm struggling with all of the indexing here. https://leetcode.com/...
3
votes
1answer
48 views

CareerCup (Bloomberg): Check if string is valid based on brackets

The goal of this problem is to determine if a string with brackets is valid. Below is a summary of the question from careercup. Check if string s is valid based on brackets ...
2
votes
1answer
63 views

Coding Challenge: Return The Smaller String

A coding challenge in which we are to write a function that compares two strings and returns the one that is smaller. The comparison is both lexicographical and numerical, depending on the content of ...
0
votes
2answers
71 views

(Leetcode) Valid parentheses

This is a Leetcode problem - Given a string containing just the characters '(', ')', '{', ...
5
votes
2answers
97 views

Character Picture Grid exercise - automatetheboringstuff

Regarding the Character picture exercise located at the end the following page: https://automatetheboringstuff.com/chapter4/ Say you have a list of lists where each value in the inner lists is a ...
1
vote
2answers
46 views

Leetcode 15 - 3 sum

This is a Leetcode problem - Given an array nums of n integers, are there elements \$a, b, c\$ in ...
7
votes
2answers
475 views

Word-Ladder solver in Python 3

Follow-up to Python program to find a word ladder transforming "four" to "five" I'm trying to write a program to solve a word ladder puzzle to brush up on my Python. For those who ...
3
votes
0answers
35 views

(Leetcode) Snakes and Ladders

This is a Leetcode problem - On an \$N\$ x \$N\$ board, the numbers from 1 to N * N are ...
4
votes
1answer
49 views

LeetCode: Intersection of two arrays ii C#

https://leetcode.com/problems/intersection-of-two-arrays-ii/ Please review for performance, I am having a problem with using TryGetValue, if someone can explain how this can be used in here. Given ...
14
votes
4answers
3k views

100-doors puzzle

Here is a very simple solution to the 100 doors challenge You are in a hotel with 100 doors. Initially every door is closed. On the first round, you change the state of every door (if it is open, ...
3
votes
1answer
68 views

LeetCode: Best Time to Buy and Sell Stock II

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ Please review for performance. Say you have an array for which the i-th element is the price of a given stock on day i. ...
2
votes
0answers
32 views

LeetCode: Remove Duplicates from Sorted Array

Please review for performance https://leetcode.com/explore/featured/card/top-interview-questions-easy/92/array/727/ Given a sorted array nums, remove the duplicates in-place such that each ...
7
votes
1answer
1k views

Python program to find a word ladder transforming “four” to “five”

I saw this Puzzling problem and thought I would try to write a Python program to solve it. The task is to transform "four" to "five", forming a new four-letter word at each step, replacing one letter ...
3
votes
1answer
48 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 ...
1
vote
0answers
104 views

LeetCode: trapping rain water C#

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. The above elevation map is represented by array [...
0
votes
2answers
128 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
2answers
935 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 ...
5
votes
3answers
122 views

Python solution for the N-Queens challenge

Here is my coded solution for the N-queens challenge The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. The program outputs all ...
6
votes
4answers
1k views

Find all letter Combinations of a Phone Number

The task is taken from LeetCode Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to letters (just ...
4
votes
1answer
55 views

Generate all possible combination of n-pair parentheses

The task is taken from LeetCode Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: ...
3
votes
1answer
178 views

Zig-zag function - coded solution

Here is my coded solution to the LeetCode zig-zag problem - The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this (you ...
0
votes
0answers
38 views

Given time intervals determine if a person could attend all meetings

The task is taken from LeetCode Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] ...
4
votes
0answers
55 views

Palindrome insertion challenge

Here is my solution to the following Daily Coding Problem challenge Given a string, find the palindrome that can be made by inserting the fewest number of characters as possible anywhere in the ...
0
votes
0answers
52 views

Given time intervals, find the minimum number of conference rooms required

The task is taken from LeetCode Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required....
1
vote
1answer
75 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 ...
2
votes
1answer
40 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 ...
0
votes
0answers
49 views

Merge Two Sorted Lists in JavaScript

The task is taken from LeetCode 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 lists. ...
1
vote
0answers
38 views

Merge k Sorted Lists

The task is taken from LeetCode Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: ...
4
votes
1answer
84 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
2answers
96 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 ...
3
votes
2answers
120 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\$ \$<=\$ ...
4
votes
0answers
87 views

Merge Intervals in JavaScript

This task is taken from Leetcode - Given a collection of intervals, merge all overlapping intervals. Example 1: ...
2
votes
0answers
75 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. ...
8
votes
2answers
2k 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
0answers
61 views

Bursting Balloons

This is a Leetcode problem - Given n balloons, indexed from 0 to n-1. Each balloon is ...
5
votes
2answers
109 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' ...
7
votes
1answer
200 views

LeetCode: last stone weight C#

https://leetcode.com/problems/last-stone-weight/ We have a collection of rocks, each rock has a positive integer weight. Each turn, we choose the two heaviest rocks and smash them together. ...
12
votes
1answer
1k views

Print the string equivalents of a phone number

Task Old mobile phones had the ability to type characters by pressing a number. The letter a could be typed by pressing 2 once. ...
6
votes
3answers
276 views

Version 2 - print new even-length arrays from two arrays

This is an update of the code for my previous post (which has now been removed as this code is more efficient and accurate) for the GeeksForGeeks task. Task outline Given two arrays, print all new ...
23
votes
7answers
6k views

Trapping Rain Water

This task is taken from Leetcode - Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. ...
13
votes
2answers
2k views

Average spam confidence

Exercise 7.2 from Python for Informatics: Write a program to prompt for a file name, and then read through the file and look for lines of the form: ...
2
votes
3answers
62 views

Jewels and Stones

The task is taken from leetcode You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you ...