instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Design a data structure to store an undo history of size k, where each undo operation must be completed in constant time complexity. Additionally, ensure that the undo history supports multiple data types, including integers, strings, and objects, and can handle a maximum of n undo operations per second. The data struc... | codefeedback |
Extract the common key words from the given two strings using a Python script. Additionally, implement a function that removes any duplicate words and sorts the resulting list alphabetically. String 1: This programming language is easy to learn. String 2: Comparing to other languages, this language is simpler. Ensure t... | codefeedback |
You need to design a calculator class with methods to perform basic calculations (add, subtract, multiply, divide, etc.). However, the calculator should only allow operations on positive integers and should throw an exception if any negative numbers or non-integer values are passed as arguments. Additionally, the calcu... | codefeedback |
Create a function in Python to rearrange the characters of each word in a given string, without using any built-in string manipulation functions or libraries. The input string will only contain alphabetic characters and spaces. The function should handle uppercase and lowercase letters properly. The rearranged words sh... | codefeedback |
Create a switch statement for printing out the day for a given number between 1 and 7, while also displaying the corresponding month and year. However, you are not allowed to use any conditional statements or loops within the switch case. You must find a way to achieve the same result using only switch cases and basic ... | codefeedback |
Please write a function in Python to print a pattern of right-angled triangles of different sizes.
The function should take two parameters: `n` (an integer representing the number of rows) and `char` (a string representing the character used to print the triangle).
The function should print a pattern of right-angled ... | codefeedback |
Understand the parameters used in the following code and explain their purpose. Additionally, ensure that the function handles cases where x is a list of integers with a length of at least 5, y is a dictionary with string keys and integer values and has at least 3 key-value pairs, and z is a boolean with a value of eit... | codefeedback |
Construct a program that finds all prime numbers between 1 and 1000 in Python.
#Instructions#
Write a program in Python that finds and prints all prime numbers between 1 and 1000.
A prime number is a whole number greater than 1 that is divisible by only 1 and itself. For example, 2, 3, 5, 7, 11, and 13 are all prim... | codefeedback |
Reverse the order of the given array, but instead of using inbuilt functions, implement your own reverse function that takes an array as input and returns a new array with the reversed order of elements. The reverse function should also have a time complexity of O(n), where n is the length of the input array. Additiona... | codefeedback |
Develop a script in Perl to sort an array in descending order, without using any built-in sorting functions. The array should only contain unique integers between 1 and 100. Your script should also print the second largest element in the sorted array. Additionally, your script should handle arrays with a size up to 10^... | codefeedback |
Given a string, remove all consecutive duplicates in the string. However, you are only allowed to use a constant amount of additional space. The original string must be modified in-place. Additionally, you must also handle cases where the consecutive duplicates occur in different cases, such as "aA" or "BB". The input ... | codefeedback |
Generate a random user agent string that includes the name, version, and operating system of a specific web browser. Additionally, the user agent string should contain a randomly generated string of characters as a unique identifier for each user. The solution should have a time complexity of O(n), where n is the lengt... | codefeedback |
Convert the Python list below to a nested dictionary of countries and their populations. The list contains additional information about the continents that each country belongs to.
List = [["United_Kingdom", "Europe", 66_000_000],["United_States", "North_America", 323_000_000], ["Brazil", "South_America", 209_000_000],... | codefeedback |
Write a code to find the longest substring of the given string with a length greater than or equal to 3 without repeating letters. Additionally, the code should return the starting and ending indices of the longest substring. The input string will only contain lowercase letters and its length will not exceed 10,000.
#... | codefeedback |
Randomly rearrange the elements of the given array and ensure that no two adjacent elements have the same value. Additionally, each element in the rearranged array must be a prime number.
nums = [12, 23, 34, 45] | codefeedback |
Write a code to add two numbers given as input, where each number is a positive integer. The sum should be calculated using only bitwise operators (e.g. AND, OR, XOR, shift operators), and the time complexity should be O(log n), where n is the maximum number of bits required to represent the input numbers.
For exampl... | codefeedback |
Write a Python function that takes a list of integers as a parameter and returns the sum of all the odd numbers in the list. The function should have a time complexity of O(n) and a space complexity of O(1). Additionally, the function should ignore negative numbers and only consider positive odd numbers. | codefeedback |
Write a code to update the content on the web page with the current time and date. The code should also display the time and date in a specific timezone, which should be determined by the user input. Additionally, the code should allow the user to choose between 12-hour and 24-hour time format for display. The code sho... | codefeedback |
Write a Python function that takes in a list of integers as input and returns a new list containing only the even numbers in the input list, sorted in ascending order. However, the function should also remove any duplicates in the output list.
To further increase the difficulty, please optimize your solution to have a... | codefeedback |
Write a Python program to format the following list of IP addresses in a specific way, where each IP address is displayed with its corresponding network address and subnet mask. The subnet mask should be represented in CIDR notation. Additionally, the program should validate the IP addresses to ensure they are valid an... | codefeedback |
Write a code snippet to query the Internet Movie Database for the release dates of all movies directed by Christopher Nolan, ensuring that the code is asynchronous and uses a callback function to handle the response. Additionally, the code should handle any potential errors that may occur during the API request and pro... | codefeedback |
Design a responsive UI layout in HTML and CSS for an e-commerce website homepage that includes a navigation bar, a hero image slider with dynamic text overlay, a product section with multiple categories and filters, a shopping cart functionality with real-time updates, a user login and registration form with encryption... | codefeedback |
Given a string of characters, write a function in Python that returns only the uppercase characters. The function should ignore any punctuation or whitespace characters in the input string. Additionally, the function should not use any built-in Python functions or libraries that directly solve the problem (e.g., `str.i... | codefeedback |
Write a function in Python that takes two strings and returns a single string with the characters in alternating order, but only for the vowels in the strings. However, the vowels should be reversed in their original order.
For example:
input: "Hello", "World!"
output: "HolWroedllo" | codefeedback |
Suggest an efficient algorithm to generate a random number between a given range in JavaScript, where the lower bound and upper bound are provided as parameters. The algorithm should ensure that the generated random number is inclusive of both the lower and upper bounds. Additionally, the solution should have a time co... | codefeedback |
Write a Python function that generates a key-value pair for the given array. The key should be the sum of all the elements in the array, and the value should be a list of all the even numbers in the array, sorted in descending order. The function should also handle cases where the array contains non-integer elements.
... | codefeedback |
Write a function in Python that takes a 2D array and returns the product of all elements in it. However, the array can contain elements of different data types, including integers, floating-point numbers, and strings. In the case of strings, the function should concatenate them instead of multiplying them. If there are... | codefeedback |
Write a function in Python that takes a list of strings and checks whether the list is empty or not. If the list is not empty, check whether all strings in the list are palindromes and have a length that is a prime number. | codefeedback |
What data structure can be used to convert the following list into a dictionary, while ensuring that all keys are unique and all values are of the same data type, and also ensuring that the dictionary is sorted in descending order based on the length of the keys? ["apple", "pear", "mango", 100, 0.25, False] | codefeedback |
Write a function that takes three arguments, a number, a list of integers, and a list of target sums. The function should return all pairs of indices in the list where the sum of the corresponding elements equals one of the target sums. The function should return the pairs in ascending order of their first index.
The ... | codefeedback |
Given a sentence, classify each word in the sentence as a noun, verb, adjective, or adverb. Additionally, for each noun, verb, adjective, or adverb, determine its tense (past, present, future) and its degree (positive, comparative, superlative). The sentence is: "The agile cat quickly climbed up the tall tree, but the ... | codefeedback |
Generate a random password with at least 16 characters that contain both upper and lowercase letters, numbers, and special characters. Additionally, the password should not contain any repeating characters. Implement the function `generate_password` which takes no arguments and returns the generated password as a strin... | codefeedback |
Given a list of positive integers, write a program which partitions the list into two non-empty parts, such that the sum of the elements in the first part is greater than or equal to twice the sum of the elements in the second part. Additionally, the difference between the sums of the two parts should be minimized.
P... | codefeedback |
Count the number of words in a sentence that begin with a consonant and end with a vowel, while also ensuring that the length of each word is less than or equal to 10 characters. | codefeedback |
Design a function which takes a parameter and returns the sum of the cubes of its digits. The parameter can be a positive integer or a string representing a positive integer. The function should handle both cases. The function should also handle negative integers as well as float numbers with decimal places. Additional... | codefeedback |
Given an array of integers, create a program that finds the longest subarray with a sum of 0. Additionally, the program should handle negative numbers and zero in the array, and find the longest subarray with a sum closest to zero.
To further increase the difficulty of this problem, add the following requirements:
1.... | codefeedback |
Implement a function in Python that prints a given string character by character, but ensure that the time complexity of your solution is O(n^2), where n is the length of the input string. Additionally, use only constant space complexity (i.e., O(1)). Your function should also handle strings that contain special charac... | codefeedback |
Write a Python class to implement a circular doubly linked list with the following additional requirements:
- The linked list should have a method to reverse the order of its elements, with a time complexity of O(n).
- The linked list should have a method to remove all elements with a specific value, with a time comple... | codefeedback |
Write code to implement a double-ended priority queue in Python, where elements can be inserted and removed from both ends of the queue. The implementation should have an average time complexity of O(log n) for insertion and removal operations, and should use a space complexity of O(n). | codefeedback |
Convert the given English sentence into a Python function definition that takes a string as an input, reverses the string, and prints it on the screen. The function should also validate if the input is a valid string and raise an exception if it is not. | codefeedback |
How can you generate a random array of 1,000,000 integers between -1,000,000 and 1,000,000, where each integer is unique and sorted in ascending order? | codefeedback |
Write a code snippet that computes the sum of all prime numbers between 1 and 1,000, excluding the numbers 2 and 3. | codefeedback |
Write a MySQL query to display the name and total salary of employees who earn more than the average salary of their department, have been employed for at least 2 years, and have a job title that starts with the letter 'S'.
Table "Employees":
Name | Department | Salary | Years Employed | Job Title
------ | -------... | codefeedback |
Write an R script that performs multiple linear regression to predict a response variable, considering at least five predictor variables and handling any missing data appropriately. Additionally, implement a cross-validation technique to evaluate the performance of the model. | codefeedback |
Write a Python function to convert a dictionary into a list of tuples. The dictionary may contain nested dictionaries as values. The output list should contain tuples where each tuple represents a key-value pair from the dictionary. If a nested dictionary is encountered, it should be flattened and represented as a sing... | codefeedback |
Write a JavaScript function to generate a random strong password with length 12-15, and must contain at least two uppercase letters, two lowercase letters, two numbers, and two special characters. | codefeedback |
Explain how Python List Comprehensions work, providing examples and discussing their time and space complexity. Additionally, provide a piece of erroneous code using list comprehensions and ask the candidate to identify and correct the error. | codefeedback |
Write a script to delete elements that appear three or more times consecutively in a list, while also ensuring that the remaining elements maintain their original order.
#Additional Requirements#
1. The script should handle lists of any length, including empty lists.
2. The script should handle lists containing eleme... | codefeedback |
Write a Python function that takes in a string and encodes it in base64. You cannot use any built-in Python libraries or functions for base64 encoding. You must implement the encoding algorithm from scratch. | codefeedback |
What is the maximum depth of a binary tree of size n if the binary tree is balanced? Please provide a step-by-step approach to calculate the maximum depth. | codefeedback |
Write a code snippet that prints out the number of times each vowel appears in a given string. The input string will only contain lowercase letters. If the string is empty, print "No vowels found".
Example:
Input: "hello"
Output:
a: 0
e: 1
i: 0
o: 1
u: 0 | codefeedback |
Implement a function in your preferred programming language that takes in a list of strings and returns the most frequent string(s) in the list. In the case of a tie, return all the strings with the highest frequency.
Provide the code for your implementation and explain the time and space complexity of your solution. | codefeedback |
Design an algorithm to check for missing numbers in an array of size n, where the array contains both positive and negative integers, and the missing numbers can be either positive or negative. Additionally, the algorithm should have a time complexity of O(n), but with an additional space complexity requirement of O(1)... | codefeedback |
Write a C program to implement a scientific calculator that can perform addition, subtraction, multiplication, division, square root, exponentiation, and logarithm operations on two numbers. The program should be able to handle floating-point numbers and display the result up to a specified number of decimal places. Ad... | codefeedback |
Create a function that takes an integer as input and returns a list of prime numbers less than that integer. The function should also check if the input is a positive integer greater than 1, and raise an exception if it is not. | codefeedback |
Create a web page with the headline "Welcome to Python programming" that uses a custom font and a background image. Additionally, the custom font should have a gradient color effect, and the background image should have a parallax scrolling effect. | codefeedback |
Write a function that takes a list as a parameter and returns only the unique elements in the given list. You may not use any built-in functions or libraries to accomplish this task. Additionally, your solution should have a time complexity of O(n^2), where n is the length of the input list.
Please note that the list ... | codefeedback |
Calculate the roots of a quadratic equation given its coefficients.
Coefficients: 3, -7, 2 | codefeedback |
Design an algorithm that prints all the permutations of a given string, but without using recursion. Additionally, the algorithm should have a time complexity of O(n!) and should not use any built-in functions or libraries for generating permutations. | codefeedback |
Write a program that takes an input array of integers and prints out every fifth element in the array. However, if the fifth element is divisible by 2, the program should print out the element multiplied by 3 instead. Additionally, if the fifth element is divisible by 3, the program should skip printing that element al... | codefeedback |
Convert a given array of numbers into a square matrix, ensuring that the sum of each row and column is equal to a given target number. Given array = [1, 2, 3, 4], target number = 10.
Provide an additional constraint that the diagonal elements of the matrix must also sum up to the target number. | codefeedback |
Create an algorithm to find the longest substring of a given string with distinct characters, where the substring must also contain at least one uppercase letter, one special character, and one digit. Given string = "abcabcabc". | codefeedback |
Write a PHP program to convert a string to a URL safe string, ensuring that special characters are properly encoded. The program should also remove any duplicate characters in the input string before encoding it. | codefeedback |
Write a Java program for binary search that operates on a sorted array of integers. The program should take an input array and a target integer as parameters and return the index of the target integer in the array. If the target integer is not found in the array, the program should return -1. The program should have a ... | codefeedback |
Write a code to print all numbers between a given range (inclusive) in the format shown below, but skip any numbers that are divisible by both 3 and 5. Additionally, the program should count and display the total number of skipped numbers.
Start = 1; End = 20; | codefeedback |
Write a code to send a message "Hello World!" using the Twilio API. The message must also include the current date and time in UTC format. Additionally, the code should handle and log any errors that may occur during the sending process. The code should be implemented in a multi-threaded manner, allowing for concurrent... | codefeedback |
Create a custom implementation of a Hashtable in Java to store a list of key-value pairs. The keys must be unique and of type String, and the values must be of type Integer. The Hashtable should have a maximum size of 100 and should not allow any null values to be added. Additionally, implement the following methods:
... | codefeedback |
Using JavaScript, create an algorithm to check if an array of numbers is sorted in ascending order, without using any built-in array methods such as sort() or reverse(). Additionally, your algorithm should have a time complexity of O(nlogn), where n is the length of the array. | codefeedback |
Rewrite this program to use an embedded loop instead of recursion. Additionally, the program should now include a constraint that the solution must have a time complexity of O(n) and a space complexity of O(1). The solution must also handle the case when the input is a negative integer and return the corresponding resu... | codefeedback |
Convert the following floating-point number to its binary representation, using the IEEE 754 standard.
Number: -7.5
1. Explain the IEEE 754 standard for representing floating-point numbers in binary format.
2. Discuss the different components of the binary representation, such as the sign bit, exponent, and mantissa.... | codefeedback |
You are given a string and you want to sort all characters in the string alphabetically in descending order. However, you are not allowed to use any built-in sorting functions or libraries. You must implement your own sorting algorithm to solve this problem. | codefeedback |
Create a SQL table with the following schema: id (integer), name (string), city (string), and email (string). The email field should only accept valid email addresses in the format "example@example.com". Additionally, implement a constraint that ensures that the email domain must be one of the following: "gmail.com", "... | codefeedback |
Create an HTML page to display the employee details with a form that allows users to update the employee information. The form should have input fields for the employee's name, age, and role. The employee details should be displayed in a table format. Additionally, implement form validation to ensure that the input fie... | codefeedback |
Write a function to implement the sequential search algorithm to find the maximum element in an array. The function should return the maximum element in the array.
The input array, arr, will contain n elements, where 1 <= n <= 10^9. Each element in the array will be an integer between -10^9 and 10^9. The function sho... | codefeedback |
You are given a string that consists of words separated by spaces. Your task is to count the number of unique words in the string. The words are case-sensitive, so "hello" and "Hello" are considered different words. You should ignore any punctuation marks or special characters that may be present within the words. Addi... | codefeedback |
Construct a code to detect if a character is an uppercase letter or not. Additionally, the code should also determine if the character is a lowercase letter or a digit. However, the code should only use bitwise operations to perform the detection. | codefeedback |
Construct a SQL query to get the sum of all the purchased items from a given table, excluding any items with a quantity less than or equal to 0, and sort the result in descending order of the purchase price. Additionally, group the result by the purchase date and display the total quantity of each purchased item.
Tabl... | codefeedback |
Implement an efficient algorithm that takes as input two positive integers and calculates their greatest common factor. The algorithm should run in O(sqrt(min(a, b))) time complexity, where a and b are the input integers. Additionally, the algorithm should not use any built-in functions or libraries for calculating the... | codefeedback |
Write a function that uses regular expressions to match two strings, where the second string must be a palindrome and contain at least one digit. Additionally, the first string must be a combination of lowercase and uppercase letters, and the second string must be a combination of lowercase letters, uppercase letters, ... | codefeedback |
Write a function in Python that takes a list of numbers as input and returns a new list with the numbers sorted in ascending order using the Radix Sort algorithm.
Note: Do not use any built-in sorting functions or methods. | codefeedback |
Override the equals method for a Java class named Point that also takes into account the color of the point and the coordinates of the point. The color can be represented as a String and should be considered when determining equality, and the coordinates should also be considered. | codefeedback |
Write a MIPS code that adds two numbers and stores the result in a given memory address, but you are not allowed to use the add instruction. You can only use bitwise operations and conditional statements to perform the addition. The two numbers to be added are stored in the registers $t1 and $t2, and the memory address... | codefeedback |
Write an SQL Query to print a list of all employees who have a higher salary than their managers, considering that each employee can have multiple managers and each manager can have multiple employees. The query should also include the department name of each employee. In addition, the query should exclude employees wh... | codefeedback |
Write Swift code to get the sum of all the prime numbers from 1 to 10000 that are also palindromes when reversed. | codefeedback |
Create a function that parses a valid IP address from a string and returns the address string without delimiters and periods. However, the function should also handle cases where the input string may contain multiple IP addresses separated by commas. In such cases, the function should return a list of the parsed IP add... | codefeedback |
Create a function to format a given phone number in the format "(123) 456-7890" and output a string with the canonical format of "+1-123-456-7890". The function should also handle cases where the phone number is passed in as a string or with additional characters such as hyphens or dots. Additionally, the function shou... | codefeedback |
Given a singly linked list, reverse it in place. The linked list can contain duplicates. Additionally, you are not allowed to use any extra data structures or recursion in your solution. Ensure that your solution has a time complexity of O(n), where n is the number of nodes in the linked list. The linked list will not ... | codefeedback |
Please write a Python script to delete duplicate elements from an array, while maintaining the original order of the elements. The array may contain both integers and strings.
Input: [1, 2, "2", 3, "3", 4, 5, "5", "5"]
Output: [1, 2, "2", 3, "3", 4, 5, "5"]
The program should go through the given array and remove any ... | codefeedback |
Write a PHP function to delete a record from a database table. The table name is "details" and the key to identify the record is "user_id". The value of the "user_id" is 10.
To increase the difficulty of the problem, add the following requirements:
1. Before deleting the record, check if the record with the specifie... | codefeedback |
Using the requests library, post a JSON object to a specified URL. However, the URL provided is incorrect and needs to be fixed in order for the code to work properly. The URL contains a randomly generated string of 10 alphanumeric characters and must be fixed by replacing a single character at a randomly chosen positi... | codefeedback |
Create a method to build a dictionary that contains all even numbers from the given list. The list may contain duplicate numbers and negative numbers as well. Additionally, the dictionary should only include even numbers that are greater than 5. | codefeedback |
Generate a SQL query to retrieve all records from the USERS table where the gender is 'Male', the age is greater than 30, and the user's name starts with the letter 'J'. | codefeedback |
Make an array containing all elements of the given list that are even, greater than 10, and less than 50. The final array should be sorted in descending order and have no repeated elements. [43,55,12,23,44] | codefeedback |
Use the requests library to make an API call to the endpoint "https://api.example.com/v1/users" with a POST request, passing a JSON payload containing a user's name, email, and password. However, the API requires authentication using an API key which needs to be included in the request headers. The API key can be obtai... | codefeedback |
Make a function in Python which calculates the covariance between two given lists.
However, the lists may contain missing values (represented by None) and the length of the two lists may not be the same. Additionally, the function should handle cases where both lists are empty or contain only missing values, and retur... | codefeedback |
Given an array of positive integers, remove all the duplicates in-place and sort the remaining unique elements in descending order. The function should modify the original array in-place and return the new length of the array.
List1 = [5, 1, 2, 3, 3, 4, 4, 2, 5, 6, 7]
Note: The solution should not use any additional d... | codefeedback |
Create a class in Java for a rectangle shape with length and breadth as attributes. The rectangle should also have a method to calculate its area and perimeter. Additionally, the rectangle's length and breadth should be prime numbers, and the maximum length or breadth should not exceed 1000. | codefeedback |
What is the purpose of this JavaScript code snippet? Ensure that the resulting string does not contain any trailing comma, and the names are sorted in alphabetical order. | codefeedback |
Create a method in JavaScript that takes a comma-separated list of values as an argument and returns an array containing those values. However, the method should also handle cases where there are leading or trailing spaces before or after each value in the list. Additionally, if any value in the list is a string enclos... | codefeedback |
Write a formula in Excel to calculate the total cost of a trip given the cost and quantity, but with the following additional constraints and requirements:
- The cost of hotel can vary depending on the day of the week. You need to retrieve the cost of hotel for each day from a separate sheet in the Excel workbook, cons... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.