{"id":22513933,"url":"https://github.com/emahtab/daily-temperatures","last_synced_at":"2026-03-19T23:02:53.470Z","repository":{"id":79525402,"uuid":"272068211","full_name":"eMahtab/daily-temperatures","owner":"eMahtab","description":"Find the days after which there will be a warmer day","archived":false,"fork":false,"pushed_at":"2024-10-12T05:26:43.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T01:42:08.670Z","etag":null,"topics":["leetcode","problem-solving","stack"],"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":"2020-06-13T18:54:38.000Z","updated_at":"2024-10-12T05:26:47.000Z","dependencies_parsed_at":"2025-02-02T03:25:32.473Z","dependency_job_id":"abe3ffbf-c7d4-459b-9bc3-859b624575ca","html_url":"https://github.com/eMahtab/daily-temperatures","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/daily-temperatures","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fdaily-temperatures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fdaily-temperatures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fdaily-temperatures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fdaily-temperatures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/daily-temperatures/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fdaily-temperatures/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262056429,"owners_count":23251676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","problem-solving","stack"],"created_at":"2024-12-07T03:15:06.728Z","updated_at":"2026-02-03T00:08:58.963Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Daily Temperatures\n## https://leetcode.com/problems/daily-temperatures\n\nGiven a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.\n```\nFor example, given the list of temperatures T = [73, 74, 75, 71, 69, 72, 76, 73], \nyour output should be [1, 1, 4, 2, 1, 1, 0, 0].\n```\n\n**Note: The length of temperatures will be in the range [1, 30000]. Each temperature will be an integer in the range [30, 100].**\n\n### Implementation : Naive\n```java\nclass Solution {\n    public int[] dailyTemperatures(int[] T) {\n        if(T == null || T.length == 0)\n            return T;\n        \n        for(int i = 0; i \u003c T.length; i++) {\n            int daysToWait = 1;\n            boolean warmerDay = false;\n            for(int j = i + 1; j \u003c T.length; j++) {\n                if(T[j] \u003e T[i]) {\n                    warmerDay = true;\n                    T[i] = daysToWait;\n                    break;\n                }\n                daysToWait++;\n            }\n            if(!warmerDay)\n                T[i] = 0;\n        }\n        return T;\n    }\n}\n```\n## Implementation 2 : Using stack (Iterating from left to right)\n```java\nclass Solution {\n    public int[] dailyTemperatures(int[] temperatures) {\n        int n = temperatures.length;\n        if(temperatures == null || n == 0)\n        return new int[0];\n        if(n == 1)\n         return new int[]{0};\n        Stack\u003cInteger\u003e stack = new Stack\u003c\u003e();\n        int[] result = new int[n];\n        for(int i = 0; i \u003c n; i++) {\n            while(!stack.isEmpty() \u0026\u0026 temperatures[i] \u003e temperatures[stack.peek()]) {\n                int index = stack.pop();\n                result[index] = i - index;\n            }\n            stack.push(i);\n        }\n        while(!stack.isEmpty()) {\n            int index = stack.pop();\n            result[index] = 0;\n        }\n        return result;\n    }\n}\n```\n## Implementation 3 : Using stack (Iterating from right to left)\n```java\nclass Solution {\n    public int[] dailyTemperatures(int[] temperatures) {\n        int n = temperatures.length;\n        if(temperatures == null || n == 0)\n          return new int[0];\n        if(n == 1)\n          return new int[]{0};\n        Stack\u003cInteger\u003e stack = new Stack\u003c\u003e();\n        int[] result = new int[n];\n        result[n-1] = 0;\n        stack.push(n-1);\n        for(int i = n-2; i \u003e= 0; i--) {\n            while(!stack.isEmpty() \u0026\u0026 temperatures[stack.peek()] \u003c= temperatures[i]) {\n                stack.pop();\n            }\n            if(stack.isEmpty())\n              result[i] = 0;\n            else   \n              result[i] = stack.peek() - i;\n            stack.push(i);\n        }\n        return result;\n    }\n}\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fdaily-temperatures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fdaily-temperatures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fdaily-temperatures/lists"}