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
5 votes
1 answer
294 views

Leetcode: Largest Number

I was trying out leetcode's Largest Number. As per the challenge's description: Given a list of non-negative integers nums, arrange them such that they form the largest number and return it. Since ...
ccot's user avatar
  • 301
2 votes
0 answers
25 views

Last Stone Weight Problem in Haskell Using `fold`

A previous solution of this code has been posted on Code Review before. This solution is more complicated then that one, but more performant (see the below) Why is this another Question instead of a ...
WesAtWork's user avatar
2 votes
3 answers
553 views

Extract data from poorly formatted phonebook

The Problem John keeps a backup of his old personal phone book as a text file. On each line of the file he can find the phone number (formated as +X-abc-def-ghij where X stands for one or two digits),...
Vessel's user avatar
  • 83
4 votes
1 answer
149 views

Last Stone Weight Problem in Haskell using list `insert`

Background Saw this problem on TheJobOverflow which seems to be a LeetCode question. It bothered me that the "challenge" of this problem was to recognize the need for a specific data-type (...
WesAtWork's user avatar
3 votes
0 answers
66 views

Sum all numbers touching symbols in 2D grid (Advent of Code 2023 Day 3, Part 1)

Please offer suggestions to my below Rust approach for solving AoC 2023 Day 3, Part 1. The code is functionally correct, so I'm interested in understanding how I could have solved it in a more ...
naivedeveloper's user avatar
4 votes
1 answer
128 views

Longest spell to cast from pages of spellbook follow-up

This question is from the PCTC 2022 R2 Past Paper and is a follow-up on my previous question. Previous question I have implemented several solutions suggested, such as creating an array with pages ...
helielicopter123's user avatar
6 votes
4 answers
556 views

Longest spell to cast from pages of spellbook

While practicing for a school coding challenge, I came across this problem. My code got the right answers but exceeded the time limited. Any tips for how to reduce the time complexity? https://pctc....
helielicopter123's user avatar
4 votes
2 answers
459 views

Leetcode: Steps to Make Array Non-decreasing

I was trying out leetcode's Steps to Make Array Non-decreasing As per the challenge's description: You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i ...
ccot's user avatar
  • 301
1 vote
3 answers
195 views

LeetCode 856: Score of Parentheses

Given a balanced parentheses string s, return the score of the string. The score of a balanced parentheses string is based on the following rule: - "()" ...
jason's user avatar
  • 21
1 vote
2 answers
120 views

Optimizing an algebraic assignment puzzle

I am going to do a math competition which allows writing programs to solve problems. The code attempts to solve problem 25 from the Purple Comet Spring 2004 Mathematics Meet: In the addition problem <...
Lucien Jaccon's user avatar
9 votes
4 answers
2k views

Leetcode : First Missing Positive

I was trying out leetcode's first missing positive. As per the challenge's description: Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an ...
ccot's user avatar
  • 301
1 vote
2 answers
78 views

Advent of Code 2023 day 1: Trebuchet (Part 2)

Task: The task involves analyzing a calibration document containing lines of text. Each line represents a calibration value that needs to be recovered by extracting the first and last digits (which ...
Harith's user avatar
  • 5,719
4 votes
3 answers
1k views

Advent of Code 2023 day 1: Trebuchet (Part 1)

Task: The task involves analyzing a calibration document containing lines of text. Each line represents a calibration value that needs to be recovered by extracting the first and last digits and ...
Harith's user avatar
  • 5,719
4 votes
2 answers
273 views

Count frequency of words and print them in sorted order

Objective: Write a program to count the frequencies of unique words from standard input, then print them out with their frequencies, ordered most frequent first. For example, given this input: ...
Harith's user avatar
  • 5,719
1 vote
1 answer
125 views

Read millions of integers from stdin and process them in Python within 2 seconds

This is a competitive programming problem which has never been solved in Python within the time limit of 2 seconds. It is about Disjoint Set Union: Source: Algorithms In Context #10: Disjoint Sets ...
Murilo Perrone's user avatar
5 votes
1 answer
120 views

Locate and multiply numbers in a 2D grid (Advent of Code 2023 Day 3, Part 2)

I am using the Advent of Code 2023 to study functional programming and the ranges library in C++. This code is for the second part of Day 3 and is the best solution using FB I've created. I'd ...
rm1948's user avatar
  • 185
6 votes
2 answers
699 views

Making a Rock Paper Scissors game in Python - How to reduce repetition and make it more effective?

I am a "new" coder to Python - saying this because I got stuck in the tutorial hell - and I saw that doing projects was a way of consolidating what I had learnt from those tutorials, so here ...
Aldis Nuts's user avatar
1 vote
0 answers
14 views

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

My 2nd take of the problem in Determine top t values with few calls to order(), a given procedure to order k values: Given an array and a procedure to order \$k\$ ...
greybeard's user avatar
  • 6,416
0 votes
2 answers
118 views

Advent of Code 2023 - Day 19: Aplenty (Part 1)

Description: The task involves processing a set of workflows, each comprising rules. These rules define conditions based on part ratings and dictate the destination workflow if the conditions are ...
Harith's user avatar
  • 5,719
4 votes
2 answers
110 views

Delete a node in binary tree

Problem Statement Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. Basically, the deletion ...
iskander's user avatar
  • 121
4 votes
1 answer
155 views

Roman numerals look and say sequence

I was practicing question 1 of the 2020 british informatics olympiad past paper: The Roman look-and-say description of a string (of Is, Vs, Xs, Ls, Cs, Ds and Ms) is made by taking each block of ...
sbottingota's user avatar
0 votes
2 answers
62 views

Advent of Code 2023 - Day 15: Lens Library

Part 1: The task involves initializing the Lava Production Facility using an initialization sequence. The sequence consists of steps, each requiring the application of the Holiday ASCII String Helper ...
Harith's user avatar
  • 5,719
0 votes
1 answer
47 views

Advent of Code 2023 - Day 9: Mirage Maintenance

Part 1: The task involves analyzing an environmental report from an oasis using the Oasis And Sand Instability Sensor (OASIS). The report consists of multiple histories, each containing a sequence of ...
Harith's user avatar
  • 5,719
0 votes
1 answer
54 views

Advent of Code 2023 - Day 8: Haunted Wasteland (Part 1)

Description: The task involves navigating a haunted wasteland on a desert island using a camel. The objective is to escape from the current position (AAA) to the destination (ZZZ) by following left/...
Harith's user avatar
  • 5,719
2 votes
1 answer
116 views

Codewars 4 Kyu kata: "Most frequently used words in a text"

This was the first kata I found hard so I wanted to ask about it. Any ways I could I have done it better? here's the question -> Most frequently used words in a text ...
Afasys's user avatar
  • 21
2 votes
3 answers
721 views

Find median value of two Sorted Arrays

To improve my coding knowledge can you please give me suggested changes on my code? ...
Subha Rajagopal's user avatar
4 votes
1 answer
103 views

Advent of Code 2023 - Day 6: Wait For It

Part One: The task involves organizing multiple toy boat races, each assigned a specific race time and a recorded distance. To surpass the existing record, participants must optimize the duration of ...
Harith's user avatar
  • 5,719
2 votes
1 answer
121 views

Advent of Code 2023 - Day 5: If You Give A Seed A Fertilizer (Part 1)

The task involves determining the lowest location number corresponding to a given set of seeds by following numerical mappings for soil, fertilizer, water, light, temperature, humidity, and location. ...
Harith's user avatar
  • 5,719
3 votes
1 answer
91 views

Finding the number of "block chains" that are a certain length and begin with a certain string

I'm currently practicing for the british informatics olympiad by doing past papers. I was doing question 3 of the 2019 paper: A set of children’s blocks, each illustrated with a single different ...
sbottingota's user avatar
3 votes
2 answers
159 views

Advent of Code 2023 - Day 4: Scratchcards

Part 1: The task involves determining the total points of a set of scratchcards. Each scratchcard contains two lists of numbers: the winning numbers and the numbers the player has. Points are awarded ...
Harith's user avatar
  • 5,719
6 votes
2 answers
207 views

Advent of Code 2023 day 1: Trebuchet (Part 1 and 2) Follow-up

This is a follow-up to the question asked here: Advent of Code 2023 day 1: Trebuchet (Part 1 and 2) Changes made: The code no longer assumes that all lines will fit into a fixed-size buffer. Although ...
Harith's user avatar
  • 5,719
1 vote
1 answer
124 views

Advent of Code 2023 - Day 2: Cube Conundrum

Part 1: The challenge involves analyzing recorded games where an Elf reveals subsets of cubes in a bag, each identified by a game ID. The goal is to determine which games would be possible if the bag ...
Harith's user avatar
  • 5,719
2 votes
2 answers
347 views

Advent of Code 2023 Day 3, Part 2 in Python

Part 2 I'm not sure if my solution covers all edge cases. The puzzle goes as follows: Given some input like this: ...
arodin's user avatar
  • 83
2 votes
0 answers
64 views

Advent of code 2023 day 9: Sequence extrapolation - in pure Bash

Part 1 Today's task involves extrapolating the next value in sequences, given in this format: 0 3 6 9 12 15 1 3 6 10 15 21 10 13 16 21 30 45 The task is to ...
janos's user avatar
  • 111k
5 votes
1 answer
159 views

Advent of Code 2023, Day 8 Part 1 - Beginner Rust Solution

Context I'm doing Advent of Code as a way of learning Rust, and have a working solution to Day 8, Part 1. This involves moving between nodes, starting at AAA and ...
F McA's user avatar
  • 53
1 vote
0 answers
29 views

Advent of code 2023 day 8: Path finding in the desert - in pure Bash

Part 1 In today's task, a network of paths is defined like this: LLR AAA = (BBB, BBB) BBB = (AAA, ZZZ) ZZZ = (ZZZ, ZZZ) The first line ...
janos's user avatar
  • 111k
4 votes
1 answer
108 views

Advent of Code 2023 day 1: Trebuchet (Part 1 and 2)

Part 1: The task involves analyzing a calibration document containing lines of text. Each line represents a calibration value that needs to be recovered by extracting the first and last digits and ...
Harith's user avatar
  • 5,719
1 vote
1 answer
81 views

Advent of Code Day 8

The task A file similar to the following is provided. ...
francesco's user avatar
0 votes
1 answer
91 views

Advent of Code 2023 day 1: Trebuchet in JS, part 2

The task involves analyzing a bunch of lines containing lines of text. Each line represents a calibration value that needs to be recovered by extracting the first and last digits and combining them ...
konijn's user avatar
  • 33.2k
2 votes
0 answers
75 views

Advent of code 2023 day 7: Ranking Camel Cards hands - mostly in Bash

Part 1 Today's task is to rank hands in a Camel Cards game and compute the total score. In Camel Cards, you get a list of hands, and your goal is to order them based on the strength of each hand. A ...
janos's user avatar
  • 111k
2 votes
1 answer
69 views

Advent of Code 2023 day 1: Trebuchet in JS

The task involves analyzing a bunch of lines containing lines of text. Each line represents a calibration value that needs to be recovered by extracting the first and last digits and combining them ...
konijn's user avatar
  • 33.2k
4 votes
1 answer
425 views

Advent of Code 2023 day 1: Trebuchet

Part 1: The task involves analyzing a calibration document containing lines of text. Each line represents a calibration value that needs to be recovered by extracting the first and last digits and ...
Harith's user avatar
  • 5,719
2 votes
0 answers
41 views

Advent of code 2023 day 6: Count ways to win boat race - in pure Bash

Part 1 To paraphrase the puzzle, given the times and record distances of boat races like this: Time: 7 15 30 Distance: 9 40 200 That is, the first ...
janos's user avatar
  • 111k
1 vote
1 answer
71 views

String represents a road. One character travels on the road obeying the stops - Code challenge (advent.js day 5)

This is my code to solve the 5th Adventjs challenge. In that link you can read the instructions. How can I improve it? It's a bit messy... and I'm repeating some part of the code. All must be in just ...
Sofia Chardin's user avatar
5 votes
2 answers
1k views

Advent of code 2023 day 4: Count scratchcard points - mostly in Bash

Yesterday I thought was the last day of Advent Of Code 2023 that I do in Bash. I was wrong. I'm not even sure anymore that today will be the one. We'll just have to see tomorrow! Part 1 To paraphrase ...
janos's user avatar
  • 111k
1 vote
0 answers
102 views

Advent of code 2023 day 3: count engine part numbers - in pure Bash

Yes I'll keep doing this until I cannot be bothered to do it in Bash ;-) (Well today is probably the last one ;-)) Part 1 To paraphrase the puzzle, given some input ("engine schematic") like ...
janos's user avatar
  • 111k
2 votes
1 answer
145 views

Advent of Code 2023 Day 2 in C#

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 ...
Natecat's user avatar
  • 123
6 votes
2 answers
1k views

Advent of code 2023 day 2: count possible qube games - 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 ...
janos's user avatar
  • 111k
5 votes
1 answer
197 views

Advent of code 2023 day 1: count trebuchet calibration numbers - 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 ...
janos's user avatar
  • 111k
1 vote
1 answer
82 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? ...
peternish's user avatar

1
2 3 4 5
66