We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
funcencryption(s:String)->String{letstrLength=s.countletsquareRootOfLength=Double(strLength).squareRoot()letcolumnCount=Int(ceil(squareRootOfLength))vargrid=[[Character]]()varencodedString=""varcolumnNumber=0varrow=[Character]()//Creating gridforcharactorins{ifcolumnNumber<columnCount{row.append(charactor)columnNumber+=1}else{grid.append(row)row.removeAll()row.append(charactor)columnNumber=1}}grid.append(row)//Creating encoded string by reading the gridforcolumnNumberin0...columnCount-1{forrowingrid{guardcolumnNumber<row.countelse{break}encodedString+=String(row[columnNumber])}encodedString+=columnNumber<columnCount?" ":""}returnencodedString}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Encryption
You are viewing a single comment's thread. Return to all comments →
Swift