File: root - text - article - 2020 - 02 - absolute-path.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 942 Views, 24569 Search Bots | 78 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 942 Views, 24569 Search Bots | 78 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Facebook:
Given a file path with folder names, '..' (Parent directory), and '.' (Current directory), return the shortest possible file path (Eliminate all the '..' and '.').
Example
Input: '/Users/Joma/Documents/../Desktop/./../'
Output: '/Users/Joma/'
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 942 Views, 24569 Search Bots | 78 Words Given a file path with folder names, '..' (Parent directory), and '.' (Current directory), return the shortest possible file path (Eliminate all the '..' and '.').
Example
Input: '/Users/Joma/Documents/../Desktop/./../'
Output: '/Users/Joma/'
def shortest_path(file_path):
# Fill this in.
print shortest_path('/Users/Joma/Documents/../Desktop/./../')
# /Users/Joma/
Related Articles
- Plus One
- Patterns for breaking down questions you haven
- Daily Interview Problem: Longest Substring With K Distinct Characters
- Algorithm Interview Question: Nth Fibonacci Number
- CVE-2015-8874 - cPanel EasyApache Vulnerabilities
- Daily Interview Problem: Merge K Sorted Linked Lists
- Algorithm Interview: Smallest Number that is not a Sum of a Subset of List
- Daily Interview Problem: Queue Using Two Stacks
- Compare Version Numbers
- Top K Frequent words
©2006~2024 SteakOverCooked - 0.00683 Seconds(s) - 2839.713 KB/s - 37 Online Memory: 492.4 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !