Chanakya

@Chanakya

Joined on Dec 15, 2022

  • Rohit travelled to America. On his return to India, he planned to bring some gadgets. He has M gadgets that weigh from 1 to M. But when Rohit travels on an aeroplane, he is only allowed to carry a maximum weight of W. So, he wants to leave some of the gadgets which are already available in India and bring the maximum number of gadgets that are not available in India. Write a program that reads the M gadgets, W weight limit and N space-separated weights of common gadgets available in India and prints the maximum number of unique gadgets that can be brought into India. Input The first line of input contains space-separated integers representing the number of gadgets M, the maximum weight limit W, and number of gadget weights N. The second line of input contains N space-separated integers representing the weights of common gadgets available in India.
     Like  Bookmark
  • Table of Contents Introduction Functions in Python Nested Functions Understanding Closures Characteristics of Python Closures Examples of Python Closures When to Use Closures Limitations of Closures Closures vs Objects
     Like  Bookmark
  • Introduction to Generators Generators are a special type of function in Python that return an iterator and allow you to iterate over a series of values lazily. Unlike normal functions that return a single value using return, generators use the yield keyword to produce a series of values one by one, without storing them all in memory at once. How Generators Work Generators are created using functions and the yield keyword. When a generator function is called, it does not execute the function body immediately. Instead, it returns a generator object that can be iterated using the next() function or a for loop. Create Python Generator In Python, similar to defining a normal function, we can define a generator function using the def keyword, but instead of the return statement we use the yield statement. def generator_name(arg):
     Like  Bookmark
  • What is an Iterable? An iterable is any Python object that you can loop over (or iterate through). Some common examples of iterables are lists, tuples, dictionaries, and strings. How to identify an Iterable: If an object can return its elements one by one, we call it iterable. It must implement the __iter__() method. Common Iterable Examples: Lists: [1, 2, 3] Strings: "Hello" Tuples: (1, 2, 3)
     Like  Bookmark
  • CSS Flexbox, or the Flexible Box Layout, is a layout model that allows you to design responsive web layouts more easily and efficiently. It provides a way to distribute space among items in a container, even when their sizes are unknown or dynamic. Flexbox is particularly useful for creating one-dimensional layouts, either in a row or a column. Flex Container: The parent element that holds flex items. You make a container a flex container by setting its display property to flex or inline-flex. Flex Items: The direct children of a flex container that will be arranged according to the flexbox model. Properties of CSS Flex Box Flex-basis Flex-grow flex-shrink
     Like  Bookmark
  • Decorator is a function, which modifies another function and returns it. The new function is often referred to as ==Decorated function==. Why to use it ? Suppose we are passing our name as an argument to a function and we want a greeting before it, let's say Hello followed by the name, then we can simply modify the function and add a hello before it, that can be the easiest way. But in case when we are working on a big project, with many functions and we want a similar modification in all of it, then changing individual function would be a lot of task and it will also effect the readability. In such cases, using decorators is advised. Before getting into the syntax of Decorators, it is important to know about how a function can be used in many ways. Functions can be assigned to variablehttps://res.cloudinary.com/deujvj7up/image/upload/v1730209278/8c347c03-a5f8-4b5f-954a-93ff27937415.png Functions can be passed as an argumenthttps://res.cloudinary.com/deujvj7up/image/upload/v1730209424/9bed2096-741f-4b21-9eb0-78362b57b995.png
     Like  Bookmark
  • King Chandragupta is waging wars to expand his kingdom. His army is powerful enough to win every battle. On a single day, Chandragupta can simultaneously wage wars on his neighboring kingdoms (i.e., the kingdoms which are in the North, South, East, and West directions). Given a map of M x N regions, where 1 indicates Chandragupta's kingdom, 0 indicates other kingdoms and x indicates barren lands (where no one lives). Find out how many days king Chandragupta require to occupy all the kingdoms on the given map. Write a program that reads a matrix M x N which represents the map and prints the number of days king Chandragupta require to occupy all the kingdoms. Input The first line of input contains two space-separated integers representing M and N respectively.
     Like  Bookmark
  • Concepts Introduction Markdown Outcome Sample RMs Instructions Formatting Guidelines Checklist Checklist
     Like  Bookmark
  • Concepts What is Java? Applications & Career Opportunities with Java <IndexItem href="section-2">Hello World Program in Java</IndexItem> <IndexItem href="section-3">Arithmetic Operations in Java</IndexItem> <IndexList> <IndexItem href="31-addition">Addition</IndexItem>
     Like  Bookmark
  • Given a matrix A of M rows and N columns, write a program to print the elements of A in a sequence that looks like a clockwise spiral form of A as shown in the image below.<br/><br/><img src='https://d1tgh8fmlzexmh.cloudfront.net/otg_prod/media/Tech_4.0/Competitive_Programming/CP_Coding_Questions_Images/searching/searching_18.png'><br/><hr><b>Input</b><br/><br/>First line contains two space separated integers M and N.<br/>Each of the following M lines contains N space separated integers.<hr><b>Output</b><br/><br/>Print space separated integers representing clockwise spiral form of A.<hr><b>Explanation</b><br/><br/>For M = 4, N = 4<br/><br/>matrix A:<br/>10 11 12 13<br/>21 22 23 14<br/>20 25 24 15<br/>19 18 17 16<br/><br/>Output:<br/>10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25<hr><b>Constraints</b><br/><br/>1 <= M, N <= 200<br/>1 <= each element of matrix <= 10^9 Test cases Input 4 6 52 18 20 5 92 89 69 61 4 60 33 49 3 87 91 41 20 2 86 81 32 36 100 34
     Like  Bookmark
  • The government has installed N CCTV cameras in a city for surveillance. The government wants to know which areas are currently under surveillance so that they can install CCTV cameras that are not under surveillance. There is a lot of data that need to be examined. The data might show some areas overlap with other areas because some CCTV cameras cover common areas. The government wants you to provide them with a summarized list of areas that are currently under surveillance by combining the common areas. For example, if the data is [[1, 3], [3, 5], [10, 15]], we can combine [1, 3], [3, 5] and provide a summarized list as [[1, 5], [10, 15]]. Write a program that reads the number of CCTV cameras N, start points and end points of CCTV cameras, and prints the summarized list of areas under surveillance in ascending order by combining the common areas. Note: The start point of a CCTV camera is always less than or equal to its end point.
     Like  Bookmark