Learn these algorithms fast to get into lucrative freelance networks

Exclusive freelance networks are an incredible way to gain consistent access to dozens of new lucrative clients.

But there’s a catch — they’re exclusive — it’s tough to get in.

It’s definitely worth it, but you’ll need to go through a grilling multi-stage process to be accepted into most of them.

Now coding quizzes are a core stage, and algorithm knowledge is crucial for you to go through.

Check these out and find out which areas you need to work on to maximize your chances of gaining entry.

The coding questions are an awesome way to test your algorithmic skills.

1. Advanced iteration

You need to know how to implement complex logic and output with while, do..while and for loops.

Common questions

How to:

  • Create shapes and structures with asterisks — like a right-angle triangle, or a pizza slice.
  • Print Fibonacci numbers until n
  • Print sum of numbers until n
JavaScript
function printFibonacci(n) { let a = 0, b = 1, temp; for (let i = 0; i < n; i++) { console.log(a); temp = a + b; a = b; b = temp; } } printFibonacci(10);

2. Arrays

Lists are everywhere in life and code.

If you want to have any chance at the algorithms you’ll meet, you need to know the in’s and out’s of inspecting and manipulating them.

Iteration, calculating sums, finding elements.

Common questions

  • Find the maximum value in an array.
  • Calculate the sum of all elements.
  • Rotate an array.
  • Find the second largest element.
  • Merge two sorted arrays.
JavaScript
function rotateArray(arr, k) { const n = arr.length; k = k % n; // in case k is greater than array length return arr.slice(-k).concat(arr.slice(0, n - k)); } // Example let arr = [1, 2, 3, 4, 5]; let k = 2; let rotatedArr = rotateArray(arr, k); console.log(rotatedArr); // Output: [4, 5, 1, 2, 3]

3. Linked Lists

Essential for lists needing efficient insertion.

Common questions

  • Re-order a linked group of words by their first element
  • Reverse a Linked List
  • Find the middle of a Linked List
  • Swap nodes in a Linked List
  • Find the starting point of a linked list

I was asked a variant of this in one of the live coding quizzes:

JavaScript
function reorderWords(pairs) { const map = Object.fromEntries(pairs); let start = pairs.find( ([from]) => !pairs.some(([, to]) => to === from) )[0]; let result = start; while (map[start]) { start = map[start]; result += start; } return result; } // Example input const pairs = [ ['G', 'A'], ['L', 'P'], ['R', 'T'], ['P', 'O'], ['O', 'R'], ['T', 'U'], ['A', 'L'], ['U', 'G'], ]; console.log(reorderWords(pairs)); // Output: 'PORTUGAL'

4. Time complexity

Time complexity evaluates how the runtime of an algorithm increases as the input size grows.

You’ll often be asked to analyze and optimize the time complexity of your solutions in coding interviews.

Common concepts

  • O(1): Constant time operations.
  • O(n): Linear time, where the runtime increases with input size.
  • O(n²): Quadratic time, often a sign that optimization is needed.

Learning how to analyze the time complexity of loops and recursive functions is key to writing efficient code.

5. Counting elements

Common questions

  • Count the number of distinct elements in an array.
  • Find how many capital letters are in a string
  • Find the majority element (appears more than half the time) in an array.
JavaScript
function findMajorityElement(arr) { let candidate = null; let count = 0; // First pass to find a candidate for (const num of arr) { if (count === 0) { candidate = num; } count += num === candidate ? 1 : -1; } // Optional second pass to confirm the candidate count = 0; for (const num of arr) { if (num === candidate) { count++; } } // Check if candidate is indeed the majority element if (count > arr.length / 2) { return candidate; } else { return null; // or throw an error if you want to indicate no majority element } } // Example usage: const arr = [3, 3, 4, 2, 4, 4, 2, 4, 4]; const majorityElement = findMajorityElement(arr); console.log(majorityElement); // Output: 4

Using data structures like hashmaps or dictionaries to count occurrences helps solve these problems efficiently.

6. Two-pointer method

A two-pointer technique used to solve problems involving subarrays, like finding subarrays with a given sum or maximum length.

Common questions

  • Find all subarrays with a given sum.
  • Determine the maximum subarray length that satisfies a condition.
JavaScript
function findSubarraysWithSum(arr, targetSum) { const result = []; let left = 0; // Left pointer let currentSum = 0; // Current sum of the window for (let right = 0; right < arr.length; right++) { currentSum += arr[right]; while (currentSum > targetSum && left <= right) { currentSum -= arr[left]; left++; } // If current sum equals targetSum, we found a subarray if (currentSum === targetSum) { result.push(arr.slice(left, right + 1)); } } return result; } // Example usage: const arr = [1, 2, 3, 7, 5]; const targetSum = 12; const subarrays = findSubarraysWithSum(arr, targetSum); console.log(subarrays); // Output: [[2, 3, 7], [7, 5]]

This technique is essential for optimizing sliding window problems.

7. Prefix sums

Prefix sums efficiently calculate the sum of elements in a subarray, enabling constant-time range queries after linear-time preprocessing.

Common questions

  • Find the sum of elements between two indices in an array.
  • Solve range sum queries efficiently.

Understanding this technique can drastically reduce the complexity of sum-based problems.

8. Sorting

Sorting is a fundamental algorithmic concept.

Bubble sort, quick sort, merge sort…

Common questions

  • Sort an array of integers.
  • Sort an array based on custom criteria.

Interviewers often expect you to recognize when sorting can simplify a problem and to implement common sorting algorithms.

9. Stacks

Stack of cards, stack of books, stack of plates…

It’s all about LIFO — Last In First out.

They’re there for problems needing backtracking or maintaining order.

Common questions

  • Evaluate expressions using stacks (e.g., reverse Polish notation).
  • Implement a stack with basic operations (push, pop, peek).

Understanding stack operations is key in solving problems like balancing parentheses or processing nested structures.

10. Leader at position

The leader in an array is an element that is greater than all elements to its right.

Identifying such elements efficiently is a common interview problem.

Common questions

  • Find all leader elements in an array.
  • Return the leader of a particular segment.

This concept help solve problems related to maximizing or minimizing values over a range.

Final thoughts

Mastering these concepts will go a long way towards acing the coding quizzes. Not just for freelance networks but for traditional job interviews.

Remember to practice not just solving problems but understanding the underlying principles behind each solution



Leave a Comment

Your email address will not be published. Required fields are marked *