My First Failed Algorithm —The Classic ‘Weighted Job Scheduling’ Problem

My First Failed Algorithm —The Classic ‘Weighted Job Scheduling’ Problem

Participating in a coding interview has to be one of the most intimidating aspects of conducting a job search as a new software developer… My First Failed Algorithm —The Classic 'Weighted Job Scheduling' ... The problem goes, given an array of jobs, each containing a start time, ...

Participating in a coding interview has to be one of the most intimidating aspects of conducting a job search as a new software developer. You have to pull yourself away from the projects you are working on, and dedicate some of that time to stretching your problem solving skills, and understanding of data structures and algorithms, just to have a shot at an offer. Problem solving can be a lot of fun, and is a source of enjoyment for many in the field, but when you have a potential offer riding on your ability to develop an optimal solution, the pressure can be immense.

My first coding challenge was a couple months ago, just as I finished bootcamp and was trying to wrap my head around heaps and Dijkstra’s algorithm. The position was for new-graduates who would be placed in a rotational program in the software team for this social media company. I felt it was a great fit for my entry level skills, and was fortunate to have my resume accepted. Then came the coding challenge. I received an email containing a link to complete an automated test within the next 3 days. I spent the first 2 blowing through an algorithm and data structure course online, hoping any of the information would stick and help me solve the problems. I hadn’t put in the time I needed in order to feel prepared to tackle the challenges.

Once I started the test I was relieved to see the first 2 questions weren’t complicated. They involved using binary search and multiple pointers, fairly easy skills to pick up and understand. Then came the third and final problem. It was a version of the classic algorithm that I had yet to encounter, the ‘Weighted Job Scheduling’ problem. The problem goes, given an array of jobs, each containing a start time, and end time, and a profit, determine the maximum profit you can obtain from completing non-overlapping jobs. The problem can be arranged in many different ways. I have seen it described as ‘2 arrays, the first array, n, containing start times of presentations, and the other array, m, containing the length of presentations, where n[i] relates to m[i]’ and you are tasked to find the maximum presentations that can take place. The input could be one or two arrays, or an object, containing more arrays or objects with keys. For my problem, the input could look like the following:

jobs = [[1,2,15],[1,3,20],[2,4,40],[3,5,75],[4,5,50],[1,4,35]]
jobs[i][0] = start-time
jobs[i][1] = end-time
jobs[i][2] = profit

So, having not practiced much dynamic programming, I was naive of the complexity of the problem, and how to solve it. I tried to brute force my way to a solution, given the first test case, but each test case proved to break my solution as the input grew and became unsorted. Long story short, I failed the challenge and did not progress in the process.

This is a problem looking for an optimal solution, and it wasn’t until I understood how to use tabulation, that I was able to crack the solution. Looking back at that input, if we try to find the optimal solution while we go through the array, it can look like this:

jobs = [[1,2,15]]
optimal solution is jobs[0] as its the only option

jobs = [[1,2,15],[1,3,20]]
optimal solution is jobs[1] as jobs[1][2] > jobs[0][2] and they conflict
jobs = [[1,2,15],[1,3,20],[2,4,40]]
now [jobs[0],jobs[2]] is the optimal solution as they don't conflict, and generate a larger combined profit than jobs[1].
jobs = [[1,2,15],[1,3,20],[2,4,40],[3,5,75]]
but now [jobs[1],jobs[3]] are optimal

As you can see, every time we consider an additional input, we have to put that in context of what we have already seen, and reevaluate what is optimal, which seems to be an complex task when dealing with large data sets. How can we keep track of every potential solution as we take in more data? The answer is tabulation.

algorithms software-development software-engineering coding flatiron-school

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Offshore Software Development - Best Practices

To make the most out of the benefits of offshore software development, you should understand the crucial factors that affect offshore development.

Software Developer vs Software Engineer — Differences: Bogus or Real?

In this article, see if there are any differences between software developers and software engineers. What you’re about to read mostly revolves around my personal thoughts, deductions, and offbeat imagination. If you have different sentiments, add them in the comment section, and let’s dispute! So, today’s topic…

Developer or Engineer? Does It Make a Difference?

To summarise the main differences between the software developer and engineer: A developer executes. ... So the software developer is mainly focused on developing code that is a part of software development cycle. An engineer designs and plans applying the principles of engineering to software development.

5 Core Criteria for Selecting Software Development Company - TopDevelopers.co

Check out these five criteria for the selection of your software vendor, and you will never regret having the wrong quality product made for you.

ERP Software Services, POS Software Services , Application Development

Vinew Technologies focused majorly over ERP Software services and POS Software services, Web & Application development services & Woo commerce and Wordpress easy-to-use, multipurpose social media plugin for WordPress.