Member-only story
PySpark: Interview Questions (Coding) — Part 2
Hi, Welcome to the next installment of my exploration into PySpark scenario-based interview questions! In this segment, I’ll continue to provide another set of interview questions and important questions from interview point of view along with code solutions.
Let’s dive in —
Q1. Cheapest and Fastest Flight
Find the cheapest and fastest airline for each travel date and mark the flights accordingly, ‘Yes’ for the flights which are cheapest or fastest and with ‘No’ for rest of the airline
Given Input —
airline| date| travel_duration| price
+ — — — -+ — — — -+ — — — — — — -+ — — — -+
indigo| 21/03/2024| 1:10| 5000
airindia| 21/03/2024| 2:00| 3500
delta| 21/03/2024| 2:00| 2000
indigo| 22/03/2024| 1:10| 5000
delta| 22/03/2024| 2:15| 1500
vistara| 22/03/2024| 1:00| 6000Output —
+ — — — — + — — — — — + — — — — — — — -+ — — -+ — — — — + — — — — +
| airline| date|travel_duration|price|cheapest|fastest|
+ — — — — + — — — — — + — — — — — — — -+ — — -+ — — — — + — — — — +
|indigo|21/03/2024| 1:10| 5000| No| Yes|
|airindia|21/03/2024| 2:00| 3500| No| No|
| delta|21/03/2024| 2:00| 2000| Yes| No|
| indigo|22/03/2024| 1:10| 5000| No| No|
| delta|22/03/2024| 2:15| 1500| Yes| No|
| vistara|22/03/2024| 1:00| 6000| No| Yes|
Sol —
from pyspark.sql import SparkSession
from…