Programmatically put site in maintenance mode - Drupal 8

In Drupal 8, the Site Maintenance status is stored in State API.

To put Site in Maintenance mode or to get Site out of Maintenance mode, we can use following code snippet: