<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/leetcode-956-hard-solution-of-the-day-tallest-billboard-swift-dp-o-n--pd9v9nncy" -->

---
title: LeetCode 956 (Hard). Solution of the day. Tallest...
description: The code uses dynamic programming to solve the problem. It maintains a dictionary dp, where the keys represent the possible height differences between the two...
canonical: https://daily.dev/posts/leetcode-956-hard-solution-of-the-day-tallest-billboard-swift-dp-o-n--pd9v9nncy
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: LeetCode 956 (Hard). Solution of the day. Tallest Billboard. Swift. DP. O(n) | daily.dev
og:description: The code uses dynamic programming to solve the problem. It maintains a dictionary dp, where the keys represent the possible height differences between the two...
og:url: https://daily.dev/posts/leetcode-956-hard-solution-of-the-day-tallest-billboard-swift-dp-o-n--pd9v9nncy
og:image: https://api.daily.dev/og/posts/pd9v9NnCy.png
og:image:alt: LeetCode 956 (Hard). Solution of the day. Tallest Billboard. Swift. DP. O(n)
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# LeetCode 956 (Hard). Solution of the day. Tallest Billboard. Swift. DP. O(n)

**[habr](https://daily.dev/sources/habr)** · 2 min read · 20 upvotes · 0 comments

## Summary

The code uses dynamic programming to solve the problem. It maintains a dictionary dp, where the keys represent the possible height differences between the two billboards. The code iterates through each rod in the given input rods. For each rod i, it creates a new dictionary cur to store the updated values for dp.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://habr.com/en/articles/743654/?utm_source=habrahabr&utm_medium=rss&utm_campaign=743654>

---

Tags: [#ios](https://daily.dev/tags/ios), [#swift](https://daily.dev/tags/swift), [#algorithms](https://daily.dev/tags/algorithms), [#swiftui](https://daily.dev/tags/swiftui)

[View this post on daily.dev](https://daily.dev/posts/leetcode-956-hard-solution-of-the-day-tallest-billboard-swift-dp-o-n--pd9v9nncy)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"LeetCode 956 (Hard). Solution of the day. Tallest Billboard. Swift. DP. O(n)","url":"https://daily.dev/posts/leetcode-956-hard-solution-of-the-day-tallest-billboard-swift-dp-o-n--pd9v9nncy","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/leetcode-956-hard-solution-of-the-day-tallest-billboard-swift-dp-o-n--pd9v9nncy"},"datePublished":"2023-06-24T08:57:08.118Z","dateModified":"2023-07-20T14:15:11.734Z","description":"The code uses dynamic programming to solve the problem. It maintains a dictionary dp, where the keys represent the possible height differences between the two...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2d35caf595ed50a642dd32af9b9ab9ef?_a=AQADKdt","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2d35caf595ed50a642dd32af9b9ab9ef?_a=AQADKdt","isAccessibleForFree":true,"articleSection":"habr","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"habr","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/habr","url":"https://daily.dev/sources/habr"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/leetcode-956-hard-solution-of-the-day-tallest-billboard-swift-dp-o-n--pd9v9nncy","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":20},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ios,swift,algorithms,swiftui","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"habr","item":"https://daily.dev/sources/habr"},{"@type":"ListItem","position":3,"name":"LeetCode 956 (Hard). Solution of the day. Tallest Billboard. Swift. DP. O(n)"}]}
```

