Author: Harish
Learn Docker for free : Building images
Docker is an open-source platform that allows developers to package, ship, and run applications in containers. Containers provide a lightweight and portable way to deploy applications, as they don’t require a full-fledged virtual machine to run. In this blog post, we will dive deep into building Docker images, exploring the various ways to create and customize your own Docker images. What is a Docker Image? A Docker image is a template that contains all the necessary files, settings, and dependencies required to run an application or service in a container. Docker images are composed of multiple layers, each representing…
Question:Program to find maximum profit in a stock numbers, basically they will give a list of number basically it should be maximum profit.example : [8,8,1,2,3,4,5,6,7,2,2]So here user can buy a stock on low price – 1, even though 8 is present it won’t yield maximum since user cant sell at 8 and buy at 1, i will be loss. So expected answer is 1-7 = 6 Input:array: A list of stock prices (e.g., [10, 7, 5, 8, 11, 9]).Algorithm:Initialize an empty list called result to store the profit differences.Iterate over each low price in the array.For each low price, iterate…
Question:Program to convert an integer number to wordsexample : input 4721 , output : four thousand and seven hundred twenty one Logic:We define dictionaries to map digits (0-9) to their corresponding words and place values (1, 10, 100, 1000) to their words.We extract each digit from the input number and find its word representation.We combine the digit word with the appropriate place word (e.g., “four” + “thousand”).Finally, we join all the words to form the complete representation.For the number 4721, the output will be “four thousand seven hundred twenty one.”Solution in python:At the time of interview give 2 implementation. We…
Simple data compression algorithm
Question:write a program for simple data compression algorithm Example: data = [1,2,3,4,0,0,0,3,4,6,0,0,0,21,2,3]out = [1,2,3,4,”3×0″,4,6,”2×0″,21,2,3] Logic:Initialize comp_count to 1 and an empty list called result.Iterate over the input list data (except for the last element).If the current element is the same as the next element, increment comp_count.If the current element is different from the next element:If there were consecutive identical elements (i.e., comp_count > 1), append the count and the element to result.Append the current element to result.Reset comp_count to 1 for the next element.Return the compressed list in the format “count x element”.Solution in python: # Example 1data = [1,2,3,4,0,0,0,3,4,6,0,0,0,21,2,3]out…
Question:Second largest number complete solutionexample : [22,3,4,5,6,11,3,33] output should be : 22 I know this is the common question asked in interview, there are number of solutions to this. But what about optimization?. This solution will give you optimized implementationLogic:Initialize two variables, large and sec_large, to None.Check if the input list l1 has at least 2 elements (using len(l1) > 1).If the condition is met, iterate through each element i in the list:If large is None or i is greater than large, update large and sec_large.Otherwise, if sec_large is None or i is between sec_large and large, update sec_large.If the…
Question:Calculate the minimum number of swaps necessary to make a string balanced Logic:Initialize sum = 0 to store the result.Maintain a count of the number of ‘[‘ brackets encountered.Reduce this count when encountering a ‘]’ character.If the count becomes negative, we must start balancing the string.Let index i represent the current position.Move forward to the next ‘[‘ at index j.Increase sum by j – i.Swap the ‘[‘ at position j with the one at position i, shifting other characters to the right.Set the count back to 1 and continue traversing the string.Solution in python: # Example usage s1 = “[]][][“…
Question:Program to find maximum profit in a stock numbers, basically they will give a list of number basically it should be maximum profit.example : [8,8,1,2,3,4,5,6,7,2,2]So here user can buy a stock on low price – 1, even though 8 is present it won’t yield maximum since user cant sell at 8 and buy at 1, i will be loss. So expected answer is 1-7 = 6 Input:array: A list of stock prices (e.g., [10, 7, 5, 8, 11, 9]).Algorithm:Initialize an empty list called result to store the profit differences.Iterate over each low price in the array.For each low price, iterate…
Question:Program to convert an integer number to wordsexample : input 4721 , output : four thousand and seven hundred twenty one Logic:We define dictionaries to map digits (0-9) to their corresponding words and place values (1, 10, 100, 1000) to their words.We extract each digit from the input number and find its word representation.We combine the digit word with the appropriate place word (e.g., “four” + “thousand”).Finally, we join all the words to form the complete representation.For the number 4721, the output will be “four thousand seven hundred twenty one.”Solution in python:At the time of interview give 2 implementation. We…
Simple data compression algorithm
Question:write a program for simple data compression algorithm Example: data = [1,2,3,4,0,0,0,3,4,6,0,0,0,21,2,3]out = [1,2,3,4,”3×0″,4,6,”2×0″,21,2,3] Logic:Initialize comp_count to 1 and an empty list called result.Iterate over the input list data (except for the last element).If the current element is the same as the next element, increment comp_count.If the current element is different from the next element:If there were consecutive identical elements (i.e., comp_count > 1), append the count and the element to result.Append the current element to result.Reset comp_count to 1 for the next element.Return the compressed list in the format “count x element”.Solution in python: # Example 1data = [1,2,3,4,0,0,0,3,4,6,0,0,0,21,2,3]out…
Question:Second largest number complete solutionexample : [22,3,4,5,6,11,3,33] output should be : 22 I know this is the common question asked in interview, there are number of solutions to this. But what about optimization?. This solution will give you optimized implementationLogic:Initialize two variables, large and sec_large, to None.Check if the input list l1 has at least 2 elements (using len(l1) > 1).If the condition is met, iterate through each element i in the list:If large is None or i is greater than large, update large and sec_large.Otherwise, if sec_large is None or i is between sec_large and large, update sec_large.If the…