Home - RobAllan27/CodingProblems GitHub Wiki
Welcome to Rob's Coding Problems wiki!
Projects tend to come with a set of test cases embedded and I have also added in some information.
Project Find Next Missing Integer In Array
Package - findNextMissingIntegerInArray
Problem Overview
This package aims to solve the following problem
- Given an array of integers, find the first missing positive integer in linear time and constant space.
- In other words, find the lowest positive integer that does not exist in the array.
- The array can contain duplicates and negative numbers as well.
Interpreted this as
- if there is array with positives in it, then find next lowest missing inter that is greater than lowest positive.
- if the existing array positive starts at N, and there are no missing integers, then return one moe thnthe greatest number
- if there is only 1 positive then return 1 greater
- if there are no positive numbers (> 0) then return 0.
Next Integer Solution -see here
Project Find If Numbers In Array Sum To Total
Package - findIfNumbersInArraySumToTotal
Problem
This package aims to deal with the following problem
Given a set of numbers, can we see if for any two numbers in the list, if added they will match a total. Given a list of numbers and target number T, return true or false whether any two numbers from the list add up to T.
- So as an example, given [9, 14, 5, 7] and T = 16, return true since 9 + 7 is 16.
- Further, how can we optimise this into one pass?
- Further, rather than just 2 numbers, return true or false if there are N numbers. So if N was 3 in the above, and T was 21 then return true as 9 + 5 + 7 = 21.
- One can assume that N will be smaller that the size of the list.
- Test cases are included in the package.
Number Sum to Solution - see here
Project Backup Calendar with Increasing Disk Storage
This project looks to create a backup calendar for a year. The program takes as an input
- N disk drives
- A calendar Date
- and a radix ā to say how often a disk cyle should run. Rather than simply rotating this disks, where a different ones is sued in strict rotation, and they are cycled, this allows some disks to hold progressively older data. If N were 7 and there was simple roarion policy then
- Disk1 on monday
- Disk2 on Tuesday etc The business rationale for this is that if a data corruption issue is only found after a period of time, we have a disk to revert back to. We only take one backup a day though
Thus if the radix is 2 (i.e. binary, then the first disk will be used) and we have 3 disks
- Day 1 ā Disk 1
- Day 2 - Disk 2
- Day 3 ā Disk 1
- Day 4 - Disk 3
- Day 5 ā Disk 1
- Day 6 - Disk 2
- Day 7 - Disk 1
- Day 8 - Disk 3 If the radix is 3, then disk 1 is used twice, then disk 2, then twice more for disk 1, then disk 2, then twice more disk A, then disk 3. Allow for cases where the user mis-calculates how many disk he need - he should have a set of n tapes (or other media) will allow backups for 2nā1 days. If he did not give you enough disks, then return the first disk. ā ie he should have 10 disks for the year ina binary system for example.
Backup Calendar - see here
Problem Given a string validate if it is well formed.
Given a string of round, curly, and square open and closing brackets, return whether the brackets are balanced (well-formed). For example, given the string "([])", you should return true. Given the string "([)]" or "((()", you should return false.
Validate Well Formed-ness Project - seehere
Project Run Length Encoder
Package - runLengthEncoder
Problem Overview
This project carries out a run length encoding and shows a single character to show the number of occurences of the following character. - for example AAABBCCC is 3A2B3C.
Run Length Encoder Project - see here
Project Subarray Sums to Target
Package - subarraysumstotarget
Problem Find sub array of integers that sum to a target - if it does retrun a sub array that matches, if there are no sub arrays that match the target return null.
Subarray Sums to Target - see here
Project Array Sum Balances
Array part adder takes an array integers and return true or false if the array can be broken into 2 sets such that
- some members are added to form a sum
- remaining members are added and form the same sum
The added members do not have to be contiguous
No items are ommitted
Package package arraypartsaddtosum;
see here
Project Attacking Bishops
Problem overview
This problem is about identifying the numbers of notional bishops of a chess board who can be attacked by other bishops.
Approach
Iterate cross the board and look for the diagonal cases lft and rights wards (upwards) and then count the number of entities above (double it to allow for bothway attacks)
Package
package attackingBishops;
see here
Project Efficient Powers
Problem Overview
This project looks at how to raise an integer to an integer power effectively. Rather than simple naive multiplication, x * x *x * x ..., if x is raised to a large power, this could be a lot of multiplications
Package package efficientpowers;
see here