Skip to main content

Posts

Lapindromes

A lapindrome is a string that, when split in the middle, gives two halves having: The same characters With the same frequency of each character If the string length is odd , the middle character is ignored . Examples of lapindromes: gaga → ga and ga abccab → abc and cab (same multiset of characters) rotor → ro and or (ignore middle t) xyzxy → xy and xy Non-examples: abbaab → halves abb and aab → same characters but frequencies differ. abcde → halves ab and de → different characters. Your task: Given a string, check if it is a lapindrome. Problem Statement: For each test case: You are given a string S (only lowercase English letters). Determine whether S is a lapindrome . Output: Print "YES" if it is a lapindrome. Print "NO" otherwise. Input Format: First line: integer T — number of test cases. Next T lines: each line contains a string S. Output Format: For each test case, print YES or NO on its own line. Constraints: 1 ≤ T ≤ 100 2 ≤ ∣S∣ ≤1000 S consists only of lo...

Leetcode 68: Text Justification

1. Problem Statement (Simple Explanation) You’re given: An array of words words (non-empty strings, no spaces inside). An integer maxWidth. You must format the text so that: Each line has  exactly maxWidth characters . Lines are  fully justified  (both left and right), except the  last line  which is  left-justified . You must pack words  greedily  in each line: take as many words as can fit in that line. You pad with spaces ' ' as necessary. Space distribution rules for non-last lines: Extra spaces between words should be distributed as  evenly as possible . If spaces do not divide evenly,  left slots  get more spaces than right slots. If a line has only  one word , it is  left-justified  (word at left, rest spaces). 2. Examples Example 1: Input: words = ["This", "is", "an", "example", "of", "text", "justification."] maxWidth = 16 Output: [   "This    is  ...