diff --git a/greedy-algorithms/src/features/encoding/solver.js b/greedy-algorithms/src/features/encoding/solver.js
index 7c7344bb7c83a81a24a9cc163affa00b9802e719..ffa56ad01436adc383f09b1d0061d3c1f83e5bbe 100644
--- a/greedy-algorithms/src/features/encoding/solver.js
+++ b/greedy-algorithms/src/features/encoding/solver.js
@@ -1,8 +1,25 @@
+import { PriorityQueue } from './collections.js';
+
 export function findEncoding(frequencies) {
   const results = new Map();
+  const partitioning = new PriorityQueue();
   for (const [meaning, frequency] of frequencies) {
     results.set(meaning, '');
+    partitioning.insert(new Set([meaning]), frequency);
+  }
+  while (partitioning.size > 1) {
+    const [firstMeaningSet, firstFrequency] = partitioning.remove();
+    const [secondMeaningSet, secondFrequency] = partitioning.remove();
+    for (const meaning of firstMeaningSet) {
+      results.set(meaning, `0${results.get(meaning)}`);
+    }
+    for (const meaning of secondMeaningSet) {
+      results.set(meaning, `1${results.get(meaning)}`);
+    }
+    partitioning.insert(
+      new Set([...firstMeaningSet, ...secondMeaningSet]),
+      firstFrequency + secondFrequency,
+    );
   }
-  // TODO: stub
   return results;
 }