Questions tagged [programming-challenge]
Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
3,301
questions
0
votes
1
answer
82
views
duplicate an open file descriptor [closed]
My program implements a function similar to `dup2'. I would like you to please find any problems with the code and what I could improve.
code:
...
4
votes
2
answers
95
views
Partition List in 2 parts
I came up with the following code while trying to solve the Leetcode partition list problem
Though my solution is accepted, I am not happy with a few of the additional variables which I am creating. ...
4
votes
2
answers
215
views
Counting primes less than n in Python
I implemented (a refinement of) the Sieve of Eratosthenes for counting primes less than a given number n. This is a coding exercise from LeetCode. The class Solution...
3
votes
2
answers
284
views
MP3 Playlist Class in Python
Background Info
I am an intermediate level Python programmer. This is my implementation of a MP3 Playlist class challenge that was hosted on 101 Computing.Net. The ...
4
votes
1
answer
151
views
Python program for the Longest Substring Without Repeating Characters
I write my Python program below for this Leetcode problem:
Given a string s, find the length of the longest substring without repeating characters.
Example 1:
...
4
votes
3
answers
2k
views
Split word based on terms from an array
I was faced with a coding challenge and I'm looking for a more elegant way to achieve the goal.
The challenge
Take the word baseball from the first item in the string
array and split it into two ...
9
votes
3
answers
3k
views
Determine if Hill or Valley
This is my accepted submission for LeetCode. The problem is
You are given a 0-indexed integer array nums. An index i is part of ...
2
votes
2
answers
453
views
Subarrays with length
You are given an array A of length N (where N is as large as 2×105). All elements of the array are positive integers less than or equal to N. Determine the count of subarrays (contiguous subsequences) ...
0
votes
1
answer
120
views
Largest product in a series
Problem description:
The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.
73167176531330624919225119674426574742355349194934
...
2
votes
3
answers
1k
views
the 10001st prime number
Problem description:
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 10001st prime number?
Prime number:
A prime number is a whole ...
3
votes
1
answer
319
views
LeetCode 68. Text Justification
I am trying out Leetcode problem 68 and I need your help to asses the code. I am pretty new to this.
Given an array of strings words and a width ...
0
votes
2
answers
195
views
Sum square difference
Problem description:
The sum of the squares of the first ten natural numbers is,
1² + 2² + … + 10² = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + … + 10)² = 55² = 3025
Hence ...
2
votes
1
answer
2k
views
The smallest positive number that is evenly divisible by all of the numbers from 1 to 20
Problem description:
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of ...
3
votes
3
answers
699
views
The largest palindrome made from the product of two 3-digit numbers
Problem description:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the ...
4
votes
2
answers
661
views
Calculate the first largest factor of 600851475143
ٍProblem description:
The prime factors of 13195 are 5, 7, 13 and 29. Largest prime factor 13195 is 29.
What is the largest prime factor of the number 600851475143 ?
Prime Factor:
any of the prime ...
4
votes
2
answers
169
views
Cleanly modifying values in hashmap for a k-sum challenge
Just started learning Rust and here's a program that has caused me some agony to implement in Rust. This is very easy to implement in C++, but Rust's borrow checker is causing all sorts of trouble. My ...
1
vote
1
answer
153
views
JavaScript function that generates Fibonacci like sequences of given order
Generalizations of Fibonacci numbers
Fibonacci numbers of higher order
A Fibonacci sequence of order \$n\$ is an integer sequence in which each
sequence element is the sum of the previous \$n\$
...
2
votes
1
answer
127
views
A simple JavaScript function that does prime factorization
This is a simple JavaScript function that does prime factorization.
I wrote it on an Android phone with online editor (I don't have access to computers in night time):
Code:
...
2
votes
2
answers
614
views
FizzBuzz in JavaScript (node.js), my first JavaScript program
I had just decided to learn JavaScript, so I wrote this program. I am sure you know what FizzBuzz is so I wouldn't describe it here.
Console output:
...
1
vote
1
answer
153
views
Infix calculator programming challenge Kattis.com
I'm working on this C++ coding problem:
Input is a sequence of up to commands, one per line, ending at
end of file. Each command is a definition, a calculation, or a clear.
All tokens within a ...
0
votes
2
answers
343
views
Algorithm for twoSum
This is my PHP algorithm for the twoSum problem in leetCode:
...
1
vote
0
answers
205
views
PyQt6 program that lets you adjust the HSV values of an RGB color
I don't know how to actually describe what this script does concisely.
I am writing GUI programs using PyQt6, and I want the most beautiful palette for my programs, so I browsed Wikipedia for a bunch ...
0
votes
2
answers
298
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
3
answers
480
views
Find local maxima of a sequence
I'm well versed in Python and Java, am just starting out with C++. Am enjoying the language and would really appreciate feedback on this solution.
kata:
Return positions and values of the "peaks&...
3
votes
1
answer
382
views
Codewars - How many pages in a book?
Problem Statement
Every book has n pages with 1 to n pages. The summary is made by adding ...
1
vote
1
answer
231
views
Finding the winner of a tic-tac-toe game in Swift
Working on the problem Find Winner on a Tic Tac Toe Game, I took several hours longer than an artificial time constraint the site had for mock interview purposes. This leads me to wonder if my ...
2
votes
1
answer
97
views
Leetcode problem: minimum removal to make valid parentheses
I was working on this problem on leetcode
Question
Your task is to remove the minimum number of parentheses ( '(' or
')', in any positions ) so that the resulting parentheses string is
valid and ...
3
votes
1
answer
143
views
Python 3 number convertor that converts floats between decimal and bases 2-36
This is a Python 3 script that converts any real number (ints and floats) from decimal notation to any positional number system ...
0
votes
1
answer
99
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 ...
0
votes
1
answer
72
views
Haskell solution to Day 2 problem of Advent of Code '21
I won't restate the problem in full, but in a nutshell you have to parse a file with a "direction" and a "magnitude", for instance:
...
0
votes
0
answers
187
views
3
votes
1
answer
249
views
Algorithm Challenge: Fuzzy Search
I recently took part in an algorithm challenge to create a Fuzzy search with the following criteria:
Given a set array, create a function that receives one argument and returns a new array containing ...
3
votes
1
answer
122
views
Function to sum all Armstrong numbers within a range
I've tried to solve a challenge posted on a LinkedIn forum using Haskell - a language I'm still learning the basics of - and, while the code works correctly, I would like to get some feedback on the ...
2
votes
1
answer
93
views
follow-up - Checking Nested Bracket Levels in Strings Programming Challenge
A follow-up to this question, this post improves on test case issues.
To restate problem parameters, a given string S is considered closed if it:
Has a matching ...
3
votes
2
answers
191
views
Programming Challenge - Capturing Bracket Levels
I don't have a formal description for this problem, but here are the parameters:
Given a string S check that each opening bracket has a matching closing bracket.
...
4
votes
0
answers
179
views
GeekTrust: Traffic problem - functional programming
First attempt to write functional programming, been following OO paradigm all through my programming journey
Please review the code and let me know if any comments and violations of functional ...
3
votes
1
answer
169
views
Array rotation in C++
I am completely new to data structures and algorithms.
I tried this problem on hackerank. I got the desired output but my code wasn't efficient enough to execute in the given time limit.
How can I ...
2
votes
2
answers
401
views
Programming Challenge: Python 3 DNS query resolver using socket
This is a DNS query resolver written in Python 3 using socket, I wrote it entirely by myself, it supports 8 primary DNS query types: A, NS, CNAME, SOA, PTR, MX, TXT,...
6
votes
0
answers
77
views
Chapter 8 Challenge: Add employee names to a department
The boring but exciting challenge:
Using a HashMap and HashSet, create a text interface to allow a user to add employee names ...
2
votes
1
answer
353
views
Programming Challenge - Game Scoring
Can this solution be made more efficient?
game_scoring.py
...
1
vote
1
answer
1k
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 ...
11
votes
2
answers
1k
views
Calculator using variable names
I've recently been assigned an assignment to create a word calculator, and given my knowledge in python is still quite lacking, I want to ask if anybody has any better ideas for any possible solutions....
6
votes
1
answer
628
views
LFU Cache implementation in Python 3
Need some feedback on this implementation of LFU cache in python3.
Original problem : https://leetcode.com/problems/lfu-cache/
Would really appreciate some feedback on readability, understandability ...
3
votes
1
answer
163
views
Highly divisible triangular number
Highly divisible triangular number, my solution
My solution of challenge from Project Euler takes too much time to execute. Although on lower numbers it works fine. Anyone could look up to my code and ...
4
votes
2
answers
759
views
Coding exercise to implement IsApproximatelyEqual in Java
this assignment was given to me within the job application process (well, really not much infos given):
for our applikation we have to compare very often floating point numbers (double, float). Can ...
3
votes
1
answer
451
views
Which fruit fall onto my house?
I am following a question on a programming challenge website (here's the original reference). What I have is a house (start & endpoint) and some types of trees at their respective location points. ...
1
vote
2
answers
99
views
It is considered a daemon if it runs in the background - creating a daemon in C
I created a daemon that creates a fifo file with a default name, then is been blocked waiting for messages on that fifo. When an interactive process writes data to that fifo, the daemon wakes up and ...
3
votes
1
answer
422
views
Maximum Depth of Binary Tree in JavaScript
The task
Given the root of a binary tree, return its maximum depth.
A binary tree's maximum depth is the number of nodes along the longest
path from the root node down to the farthest leaf node.
...
2
votes
0
answers
37
views
Maximum length of a row made up from given dominoes
Given a set of dominoes, find the maximum length of a row that can be made using some of those dominoes. Rotating the dominoes is allowed.
Recall: A domino piece consists of 2 numbers from 0 to 6 (e....
4
votes
1
answer
565
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 ...