Skip to content

Instantly share code, notes, and snippets.

@keitaito
Last active January 27, 2017 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keitaito/41befe6526a8d978fe1c150af9a48d70 to your computer and use it in GitHub Desktop.
Save keitaito/41befe6526a8d978fe1c150af9a48d70 to your computer and use it in GitHub Desktop.
//
// main.swift
// DesignerPDFViewer
//
// Created by Keita Ito on 1/26/17.
// Copyright © 2017 Keita Ito. All rights reserved.
//
// The link to the challenge: https://www.hackerrank.com/challenges/designer-pdf-viewer
let heights = readLine()!.characters.split(separator: " ").map { Int(String($0))! }
let word = readLine()!
let scalarValuesOfWord = word.unicodeScalars.map { Int($0.value) }
let scalarValueOfA = Int(UnicodeScalar("a")!.value)
let adjustedScalarValuesOfWord = scalarValuesOfWord.map { $0 - scalarValueOfA }
let heightsOfWord = adjustedScalarValuesOfWord.map { heights[$0] }
let heightOfMaxElement = heightsOfWord.max()!
let result = heightOfMaxElement * word.characters.count
print(result)
// The link to the challenge: https://www.hackerrank.com/challenges/designer-pdf-viewer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment