{"id":22513437,"url":"https://github.com/emahtab/text-justification","last_synced_at":"2026-03-19T23:02:40.376Z","repository":{"id":261548158,"uuid":"884632796","full_name":"eMahtab/text-justification","owner":"eMahtab","description":"Text Justification","archived":false,"fork":false,"pushed_at":"2024-11-07T05:45:19.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-14T08:58:36.469Z","etag":null,"topics":["leetcode","text-justification"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-07T05:26:39.000Z","updated_at":"2024-11-07T05:58:43.000Z","dependencies_parsed_at":"2024-11-07T06:27:16.103Z","dependency_job_id":"230ca728-bf23-4028-ab25-144ed134592c","html_url":"https://github.com/eMahtab/text-justification","commit_stats":null,"previous_names":["emahtab/text-justification"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/text-justification","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ftext-justification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ftext-justification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ftext-justification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ftext-justification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/text-justification/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ftext-justification/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29332292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T06:13:03.264Z","status":"ssl_error","status_checked_at":"2026-02-11T06:12:55.843Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["leetcode","text-justification"],"created_at":"2024-12-07T03:12:20.949Z","updated_at":"2026-02-11T11:01:45.870Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Text Justification\n## https://leetcode.com/problems/text-justification\n\nGiven an array of strings words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.\n\nYou should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.\n\nExtra spaces between words should be distributed as evenly as possible. If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.\n\nFor the last line of text, it should be left-justified, and no extra space is inserted between words.\n\nNote:\nA word is defined as a character sequence consisting of non-space characters only.\nEach word's length is guaranteed to be greater than 0 and not exceed maxWidth.\nThe input array words contains at least one word.\n \n```\nExample 1:\n\nInput: words = [\"This\", \"is\", \"an\", \"example\", \"of\", \"text\", \"justification.\"], maxWidth = 16\nOutput:\n[\n   \"This    is    an\",\n   \"example  of text\",\n   \"justification.  \"\n]\nExample 2:\n\nInput: words = [\"What\",\"must\",\"be\",\"acknowledgment\",\"shall\",\"be\"], maxWidth = 16\nOutput:\n[\n  \"What   must   be\",\n  \"acknowledgment  \",\n  \"shall be        \"\n]\nExplanation: Note that the last line is \"shall be    \" instead of \"shall     be\", because the last line must be left-justified instead of fully-justified.\nNote that the second line is also left-justified because it contains only one word.\nExample 3:\n\nInput: words = [\"Science\",\"is\",\"what\",\"we\",\"understand\",\"well\",\"enough\",\"to\",\"explain\",\"to\",\"a\",\"computer.\",\"Art\",\"is\",\"everything\",\"else\",\"we\",\"do\"], maxWidth = 20\nOutput:\n[\n  \"Science  is  what we\",\n  \"understand      well\",\n  \"enough to explain to\",\n  \"a  computer.  Art is\",\n  \"everything  else  we\",\n  \"do                  \"\n]\n``` \n\n### Constraints:\n\n1. 1 \u003c= words.length \u003c= 300\n2. 1 \u003c= words[i].length \u003c= 20\n3. words[i] consists of only English letters and symbols.\n4. 1 \u003c= maxWidth \u003c= 100\n5. words[i].length \u003c= maxWidth\n\n# Implementation :\n```java\nclass Solution {\n    public List\u003cString\u003e fullJustify(String[] words, int maxWidth) {\n        List\u003cString\u003e ans = new ArrayList\u003c\u003e();\n        int i = 0;\n        while (i \u003c words.length) {\n            List\u003cString\u003e currentLine = getWords(i, words, maxWidth);\n            i += currentLine.size();\n            ans.add(createLine(currentLine, i, words, maxWidth));\n        }\n        return ans;\n    }\n\n    private List\u003cString\u003e getWords(int i, String[] words, int maxWidth) {\n        List\u003cString\u003e currentLine = new ArrayList\u003c\u003e();\n        int currLength = 0;\n        while (i \u003c words.length \u0026\u0026 currLength + words[i].length() \u003c= maxWidth) {\n            currentLine.add(words[i]);\n            currLength += words[i].length() + 1;\n            i++;\n        }\n        return currentLine;\n    }\n\n    private String createLine(List\u003cString\u003e line, int i, String[] words, int maxWidth) {\n        int actualLineLength = -1;\n        for (String word : line) {\n            actualLineLength += word.length() + 1;\n        }\n        int extraSpaces = maxWidth - actualLineLength;\n        if (line.size() == 1 || i == words.length) {\n            return String.join(\" \", line) + \" \".repeat(extraSpaces);\n        }\n        int wordsToAdjustSpaces = line.size() - 1;\n        int spacesPerWord = extraSpaces / wordsToAdjustSpaces;\n        int needsExtraSpace = extraSpaces % wordsToAdjustSpaces;\n        for (int j = 0; j \u003c wordsToAdjustSpaces; j++) {\n            line.set(j, line.get(j) + \" \".repeat(spacesPerWord));\n        }\n        for (int j = 0; j \u003c needsExtraSpace; j++) {\n            line.set(j, line.get(j) + \" \");\n        }\n        return String.join(\" \", line);\n    }\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Ftext-justification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Ftext-justification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Ftext-justification/lists"}