Questions tagged [programming-challenge]

Use this tag when the code is a solution to a programming challenge. Always include a sufficient description of the problem to be solved - while a link to the challenge is welcome, the review request needs to be complete when the challenge site is unavailable.

Filter by
Sorted by
Tagged with
2 votes
0 answers
6 views

Advent of code 2023 day 2 in pure Bash

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 ...
4 votes
1 answer
70 views

Advent of code 2023 day 1 mostly in Bash

It's that time of the year again! Although there's no more Winter Bash, we can still have all the Bash we want in winter ;-) Part 1 To paraphrase the description: For each line in the input: Find ...
0 votes
1 answer
25 views

Print a hollow Rhombus [closed]

I am beginner in java, here is my code to print a hollow rhombus: ...
0 votes
1 answer
63 views

HackerRank Algorithm Problem: Climbing the Leaderboard (Python)

Here is the Hackerrank problem which is related to dense ranking and below is my solution which didn't pass the time limit cases. Any better way to optimize this? ...
2 votes
2 answers
151 views

Given an array, remove zero or more elements to maximize the reduction where you add odd values and subtract even values

Here's a code challenge I got. (I could not solve the challenge, I ran out of time. I rephrased the challenge language and I am trying the challenge again for personal growth & computer science ...
-1 votes
1 answer
102 views

HackerRank Project Euler 12 (Python) | Highly Divisible Triangular Numbers

I again share my Python code which didn't pass time limit test cases in the HackerRank contest of ProjectEuler. ...
3 votes
2 answers
260 views

Trailing Digits

https://www.acmicpc.net/problem/23204 I've solved a programming challenge where you need to count the occurrences of a specific digit at the end of the product of multiples of a given number within a ...
3 votes
1 answer
196 views

Project Euler 60: Prime Pair Sets

Project Euler Prime Pair Sets: The primes 3, 7, 109, and 673 are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 ...
1 vote
1 answer
69 views

Project Euler 10(Python) | Summation of Primes

This is my Python3 code which solved the 10th problem of Project Euler. I haven't passed the last 2 time limit test cases. ...
4 votes
1 answer
4k views

Largest rectangle areas after drawing boundaries

I was asked the following question while trying to get a Hackerrank certificate. I couldn't solve on time but I now completed the solution. Can you please check if my solution seems good? Suggestions ...
2 votes
1 answer
90 views

Codeforces: Dasha & Nightmares

so I got started with competitive programming about a day ago and I got stuck on the first random question I tried on codeforces. It's called Dasha and Nightmares. Problem Description: The problem ...
1 vote
0 answers
27 views

Determine top t values with few calls to order(), a given procedure to order k values

Trying to write a decent answer to Most efficient way to get the largest 3 elements of an array using no comparisons but a procedure for ordering 5 elements descendantly, I came up with something ugly....
7 votes
3 answers
21k views

Output two columns

Output formatting: Input Format Every line of input will contain a String followed by an integer. Each String will have a maximum of 10 alphabetic characters, and each integer will be in the ...
4 votes
2 answers
987 views

Introduction to Haskell: Validating credit card numbers

I have implemented the introductory challenge of University of Pennsylvania's CIS 194: Introduction to Haskell (Spring 2013) course. I have added the most important information of the problem ...
5 votes
1 answer
303 views

Find the starting indices of all occurrences of the pattern in the string - KMP algorithm follow-up

The task was initially solved here, but was too buggy: Given a string and a pattern, find the starting indices of all occurrences of the pattern in the string. For example, given the string "...
1 vote
5 answers
246 views

Sum of bitwise XOR of each subarray weighted by length

here is the problem statement You are given an array a of length n consisting of non-negative integers. You have to calculate the value of \$\sum_{l=1}^n \sum_{r=l}^n f(l,r)\cdot (r - l + 1)\$ where \...
12 votes
3 answers
501 views

C++, sort integers using knowledge of entire vector

I am solving the "Sort" problem on Kattis. Mirko is a great code breaker. He knows any cipher in the world can be broken by frequency analysis. He has completely the wrong idea what ...
3 votes
3 answers
238 views

Increment a large integer represented as array of digits

This problem can be found at LeetCode. Since I was studying idiomatic or 'pythonic' code in my language today, I decided to take the most 'pythonic' approach and challenged myself to do this in one ...
2 votes
1 answer
88 views

Project Euler Problem 1: Multiples of 3 or 5

The following is my solution to Project Euler Problem 1: Multiples of 3 or 5. ...
2 votes
2 answers
902 views

InterviewBit Problem: Stringoholics

I am trying to solve this InterviewBit problem. Problem Statement: You are given an array A consisting of strings made up of the letters ‘a’ and ‘b’ only. Each string goes through a number of ...
0 votes
3 answers
633 views

Project Euler #12 (Highly divisible triangular numbers) in Python 3.x

I'm a beginner to programming and just started python, I've been trying to work through Project Euler challenges. I wrote a program to solve Project Euler #12, which asks for the smallest number of ...
-1 votes
1 answer
2k views

Project Euler Problem #12 - Highly divisible triangular number

Project Euler Problem #12 The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would ...
1 vote
1 answer
264 views

Project Euler # 21 amicable numbers Python

Let \$d(n)\$ be defined as the sum of proper divisors of \$n\$ (numbers less than \$n\$ which divide evenly into \$n\$). If \$d(a) = b\$ and \$d(b) = a\$, where \$a ≠ b\$, then \$a\$ and \$b\$ are an ...
-1 votes
1 answer
76 views

Integer pairs with more than 3 common divisors

findPairs produces the Integer pairs so that the numbers from 1 to N and the pair of numbers have a sum less than 50 and have more than 3 common divisors. Could ...
6 votes
3 answers
2k views

Finding the first triangle number with over five hundred divisors

Project Euler Problem #12: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms ...
1 vote
1 answer
384 views

Project Euler #211: Divisor Square Sum

I started doing hackerrank problems only recently and here's my attempt to solve this problem. Basically, you're given two integers N and ...
5 votes
2 answers
229 views

Deficient Numbers

I have found the following interesting challenge on the web: Deficient Numbers A number is considered deficient if the sum of its factors is less than twice that number. For example: 10 is a ...
2 votes
2 answers
312 views

Project Euler 378: Count ordered triplets whose triangular numbers have decreasing number of factors

Project Euler problem 378 says: Let \$T(n)\$ be the \$n\$th triangle number, so \$T(n) = {n (n+1) \over 2}\$. Let \$\mathit{dT}(n)\$ be the number of divisors of \$T(n)\$. E.g.: \$T(7) = 28\$...
1 vote
3 answers
1k views

Display a number as a product of its prime factors

Task: Link to original problem :https://www.spoj.com/problems/FACTCG2/ The task in this problem is to write a number in a multiplication of prime numbers separated by “...
1 vote
3 answers
845 views

Kattis prime reduction challenge

I am solving the Prime Reduction challenge on Kattis. Consider the following process, which we’ll call prime reduction. Given an input x: if x is prime, print x and stop factor x into its ...
1 vote
2 answers
265 views

Work out largest prime factor of a number

I am trying to get better at problem solving, so I am going through challenges on Project Euler. Problem: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the ...
3 votes
1 answer
129 views

Project Euler problem #3

My code works but would take 160 days to run lol. ...
11 votes
5 answers
3k views

A faster way to compute the largest prime factor

I am self-learning js and came across this problem(#3) from the Euler Project The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? ...
0 votes
1 answer
123 views

A faster way to compute largest prime factor (Again, but a lot better)

I came up with this code after implementing the feedback given by @200_success. The previous one (A faster way to compute the largest prime factor) tested my patience, but still failed to give the ...
5 votes
1 answer
300 views

Finding sum of divisors of numbers between the range (1 to 1e16)

The exact link to the question : https://www.spoj.com/problems/DIVSUM2/ Input: An integer stating the number of test cases (equal to 500), and that many lines follow, each containing one integer ...
2 votes
2 answers
895 views

Project Euler #3 with Python

I tried to solve some Euler's problems, this is the solution I found for problem #3 with Python. The problem asks: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor ...
0 votes
2 answers
178 views

Project Euler problem # 3 is this the most efficient approach in Python or can I do better?

The problem statement: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? This code takes 9 seconds!, is there a better way? ...
4 votes
2 answers
81 views

Project Euler - Problem 3

The description of the problem is: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Here is my solution: ...
1 vote
3 answers
129 views

C++ For Euler Problem 3

Here's my solution for Euler Problem 3: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I'm using the Euler problems to learn some ...
2 votes
2 answers
318 views

Finding the nth ugly number

I'm trying to optimize my solution to this LeetCode problem: Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the ...
6 votes
3 answers
262 views

Project Euler 21: Sum of amicable numbers optimisation

Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b ...
6 votes
2 answers
685 views

Euler 12: counting divisors of a triangle number

This is the question: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: ...
2 votes
1 answer
239 views

Hackerrank problem -"Another Prime Problem"

I came across this issue in the problem titled: Another Prime Problem. Here's my solution with JavaScript which passed test case-1, but for other test cases it led to timeout. ...
1 vote
1 answer
183 views

LeetCode 952: Largest Component Size by Common Factor

I'm posting my code for a LeetCode problem copied here. If you would like to review, please do so. Thank you for your time! Problem Given a non-empty array of unique positive integers A, consider the ...
3 votes
1 answer
958 views

Python code to find greatest common divisor of multiple numbers

Hmm, I know this has been implemented countless times, and Python 3.9.5 math standard library has a built-in gcd() method that ...
1 vote
0 answers
62 views

Euler Project Problem #3 Optimization Needed

Well I was solving Problem 3 from Project Euler, but I just found out that my code is really bad, it would take so much time to finish processing the code and I honestly do not know how to optimize it....
3 votes
1 answer
214 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
897 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 ...
2 votes
1 answer
3k 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 ...
5 votes
1 answer
81 views

Möbius function using iterators for prime factors

While working on Project Euler, I have come across a few questions involving usage of the little omega function, big omega function, and Möbius function. My prior code wrote factors into an array and ...

1
2 3 4 5
67