Complete competitive-coding-3#1177
Complete competitive-coding-3#1177paridhimalviya wants to merge 1 commit intosuper30admin:masterfrom
Conversation
Interview Problem : Pascal's Triangle (PascalsTriangle.swift)Your solution is correct and handles the problem as required. Here are some suggestions for improvement:
Here's a revised version of your code for reference: func generate(_ numRows: Int) -> [[Int]] {
guard numRows > 0 else { return [] }
var result = [[1]]
for i in 1..<numRows {
var row = [1]
let prevRow = result[i-1]
for j in 1..<i {
row.append(prevRow[j-1] + prevRow[j])
}
row.append(1)
result.append(row)
}
return result
}This version is more streamlined and handles all rows uniformly. VERDICT: PASS Interview Problem: Pairs with K difference (PairsWithKDiff.swift)Your solution However, your first solution For the problem constraints, the map-based solution is preferable because it is straightforward and avoids potential issues with ordering during traversal. I recommend using the VERDICT: PASS |
-> Pascal's triange
-> Pairs with k difference